javascript scissors paper rock


SUBMITTED BY: Guest

DATE: April 12, 2013, 10:40 a.m.

FORMAT: JavaScript

SIZE: 908 Bytes

HITS: 1200

  1. var userChoice = prompt("paper scissors rock");
  2. var x = Math.floor(Math.random() * 3 + 1);
  3. console.log(x);
  4. if ((userChoice === "paper") && (x === 1)) {alert("draw");}
  5. else if ((userChoice === "paper") && (x === 2 )) {alert("scissors beats paper");}
  6. else if ((userChoice === "paper") && (x === 3 )) {alert("paper beats rock");}
  7. else if ((userChoice === "rock") && (x === 1 )) { alert("paper beats rock");}
  8. else if ((userChoice === "rock") && (x === 2 )) { alert("rock beats scissors");}
  9. else if ((userChoice === "rock") && (x === 3 )) { alert("draw");}
  10. else if ((userChoice === "scissors") && (x === 1 )) { alert("scissors beats paper");}
  11. else if ((userChoice === "scissors") && (x === 2 )) { alert("draw");}
  12. else if ((userChoice === "scissors") && (x === 3 )) { alert("rock beats scissors");}
  13. console.log(x);

comments powered by Disqus