Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rps() {
- var playornah = confirm('Do you want to play Rock Paper Scissors?')
- if (playornah == true) {
- playRPS();
- }
- function playRPS() {
- var userChoice = prompt('Choose Rock, Paper, or Scissors!\n\n \(All lowercase.\)')
- switch (Math.round(Math.random() * (3- 1) + 1)) {
- case 1:
- compChoice = "rock";
- break;
- case 2:
- compChoice = "paper";
- break;
- case 3:
- compChoice = "scissors";
- break;
- }
- if (compChoice == "rock" && userChoice == "rock") {
- playagain = confirm('It was a tie!\nBoth opponents chose Rock!\n\nPlay again?')
- if (playagain == true) {
- playRPS();
- } else {
- alert('Closing Game.')
- }
- } else if (compChoice == "paper" && userChoice == "paper") {
- playagain = confirm('It was a tie!\nBoth opponents chose Paper!\n\nPlay again?')
- if (playagain == true) {
- playRPS();
- } else {
- alert('Closing Game.')
- }
- } else if (compChoice == "scissors" && userChoice == "scissors") {
- playagain = confirm('It was a tie!\nBoth opponents chose Scissors!\n\nPlay again?')
- if (playagain == true) {
- playRPS();
- } else {
- alert('Closing Game.')
- }
- } else if (compChoice == "rock" && userChoice == "scissors") {
- playagain = confirm('You lost!\nThe opponent chose Rock, while you chose Scissors!\n\nPlay again?')
- if (playagain == true) {
- playRPS();
- } else {
- alert('Closing Game.')
- }
- } else if (compChoice == "rock" && userChoice == "paper") {
- playagain = confirm('You won!\nThe opponent chose Rock, while you chose Paper!\n\nPlay again?')
- if (playagain == true) {
- playRPS();
- } else {
- alert('Closing Game.')
- }
- } else if (compChoice == "paper" && userChoice == "rock") {
- playagain = confirm('You lost!\nThe opponent chose Paper, while you chose Rock!\n\nPlay again?')
- if (playagain == true) {
- playRPS();
- } else {
- alert('Closing Game.')
- }
- } else if (compChoice == "paper" && userChoice == "scissors") {
- playagain = confirm('You won!\nThe opponent chose Paper, while you chose Scissors!\n\nPlay again?')
- if (playagain == true) {
- playRPS();
- } else {
- alert('Closing Game.')
- }
- } else if (compChoice == "scissors" && userChoice == "rock") {
- playagain = confirm('You won!\nThe opponent chose Scissors, while you chose Rock!\n\nPlay again?')
- if (playagain == true) {
- playRPS();
- } else {
- alert('Closing Game.')
- }
- } else if (compChoice == "scissors" && userChoice == "paper") {
- playagain = confirm('You lost!\nThe opponent chose Scissors, while you chose Paper!\n\nPlay again?')
- if (playagain == true) {
- playRPS();
- } else {
- alert('Closing Game.')
- }
- } else if (userChoice == null) {
- alert('Closing Game.')
- } else {
- alert('Invalid Input.\nPlease type all inputs in lowercase with correct spelling.')
- playRPS();
- }
- }
- }
- rps();
Add Comment
Please, Sign In to add comment