Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var dice1 = Math.floor(Math.random() * 5) + 1;
- var dice2 = Math.floor(Math.random() * 5) + 1;
- alert('Lets shake some dice!');
- while (player < 5 && computer < 5)
- {
- playerScore = dice1 + dice2;
- alert('Your turn to roll' + '\n You shook a ' + dice1 + ' and a ' + dice2 + ' , so you have ' + playerScore);
- dice1 = Math.floor(Math.random() * 5) + 1;
- dice2 = Math.floor(Math.random() * 5) + 1;
- computerScore = dice1 + dice2;
- alert('My turn to roll' + '\n I shook a ' + dice1 + ' and a ' + dice2 + ' , so I have ' + computerScore);
- dice1 = Math.floor(Math.random() * 5) + 1;
- dice2 = Math.floor(Math.random() * 5) + 1;
- if (computerScore > playerScore)
- {
- computer++;
- }
- else if (computerScore < playerScore)
- {
- player++;
- }
- if (playerScore > computerScore)
- {
- alert('You win ' + playerScore + ' to ' + computerScore + '\nYou are winning ' + player + ' to ' + computer)
- }
- else if (playerScore < computerScore)
- {
- alert('I win ' + computerScore + ' to ' + playerScore + '\nI am winning ' + computer + ' to ' + player)
- }
- if (playerScore == computerScore && player == computer)
- {
- alert('You win ' + playerScore + ' to ' + computerScore + '\nThe score is tied ' + player + ' to ' + computer)
- }
- else if (playerScore == computerScore && player > computer)
- {
- alert('Tie! Roll again!' + '\nYou are winning ' + player + ' to ' + computer)
- }
- else if(playerScore == computerScore && player < computer)
- {
- alert('Tie! Roll again!' + '\nI am winning ' + computer + ' to ' + player)
- }
- }
- if (computer == 5)
- {
- alert('I win ' + computer + ' to ' + player + '\n I win the game!')
- }
- else if (player == 5)
- {
- alert('You win ' + player + ' to ' + computer + '\n You win the game!')
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement