Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. <script>
  2. var player = 0;
  3. var computer = 0;
  4. var varplayerScore;
  5. var computerScore;
  6. var dice1 = Math.floor(Math.random() * 5) + 1;
  7. var dice2 = Math.floor(Math.random() * 5) + 1;
  8.  
  9. alert('Lets shake some dice!');
  10.  
  11. while (player < 5 && computer < 5)
  12. {
  13. playerScore = dice1 + dice2;
  14. alert('Your turn to roll' + '\n You shook a ' + dice1 + ' and a ' + dice2 + ' , so you have ' + playerScore);
  15. dice1 = Math.floor(Math.random() * 5) + 1;
  16. dice2 = Math.floor(Math.random() * 5) + 1;
  17. computerScore = dice1 + dice2;
  18. alert('My turn to roll' + '\n I shook a ' + dice1 + ' and a ' + dice2 + ' , so I have ' + computerScore);
  19. dice1 = Math.floor(Math.random() * 5) + 1;
  20. dice2 = Math.floor(Math.random() * 5) + 1;
  21. if (computerScore > playerScore)
  22. {
  23. computer++;
  24. }
  25. else if (computerScore < playerScore)
  26. {
  27. player++;
  28. }
  29. if (playerScore > computerScore)
  30. {
  31. alert('You win ' + playerScore + ' to ' + computerScore + '\nYou are winning ' + player + ' to ' + computer)
  32. }
  33. if (playerScore > computerScore && player == computer)
  34. {
  35. alert('You win ' + playerScore + ' to ' + computerScore + '\nThe score is tied ' + player + ' to ' + computer)
  36. }
  37. else if(playerScore < computerScore && player == computer)
  38. {
  39. alert('You win ' + playerScore + ' to ' + computerScore + '\nThe score is tied ' + player + ' to ' + computer)
  40. }
  41. else if (playerScore < computerScore)
  42. {
  43. alert('I win ' + computerScore + ' to ' + playerScore + '\nI am winning ' + computer + ' to ' + player)
  44. }
  45. else if (computerScore == playerScore && player > computer)
  46. {
  47. alert('Tie! Roll again!' + '\nYou are winning ' + player + ' to ' + computer)
  48. }
  49. else if (computerScore == playerScore && computer > player)
  50. {
  51. alert('Tie! Roll again!' + '\nI am winning ' + computer + ' to ' + player)
  52. }
  53.  
  54. }
  55. if (computer == 5)
  56. {
  57. alert('I win ' + computerScore + ' to ' + playerScore + '\n I win the game!')
  58. }
  59. else if (player == 5)
  60. {
  61. alert('You win ' + playerScore + ' to ' + computerScore + '\n You win the game!')
  62. }
  63.  
  64. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement