Advertisement
Chemist-i

program from codacademy.com

Feb 12th, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //game 2, rock, scissors, paper
  2.  
  3. var userChoice = prompt("Do you choose rock, paper or scissors?");
  4. var computerChoice = Math.random();
  5. if (computerChoice < 0.34) {
  6.     computerChoice = "rock";
  7. } else if(computerChoice <= 0.67) {
  8.     computerChoice = "paper";
  9. } else {
  10.     computerChoice = "scissors";
  11. } console.log("Computer: " + computerChoice);
  12.  
  13. var compare = function (choice1, choice2) {
  14.     if (choice1 === choice2)
  15.         return "The result is a tie!";
  16.     else if (choice1 === "rock") {
  17.         if (choice2 === "scissors")
  18.             return "rock wins";
  19.         else
  20.             return "paper wins";
  21.     } else if (choice1 === "paper") {
  22.         if (choice2 === "rock")
  23.             return "paper wins";
  24.         else
  25.             return "scissors wins";
  26.     } else { //choice1 === scissors
  27.         if (choice2 === rock) {
  28.             return wins + rock;
  29.         } else {
  30.             return wins + scissors;
  31.         }
  32. }
  33. console.log( compare(userChoice, computerChoice) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement