1 function playRockPaperScissors() 2 {//Rock, Paper, Scissors 3 let rounds = prompt("How many rounds of rock, paper, scissors do you want to play?"); 4 rounds = parseInt(rounds); 5 let wins = 0; 6 let losses = 0; 7 let draws = 0; 8 9 for (let i = 0; i < rounds; i++) 10 { 11 let computerMove; 12 let computerChoice = Math.floor(Math.random() * 3); 13 14 if (computerChoice === 0) 15 { 16 computerMove = "r"; //rock 17 } 18 else if (computerChoice === 1) 19 { 20 computerMove = "p"; //paper 21 } 22 else 23 { 24 computerMove = "s"; //scissors 25 } 26 27 let playerChoice = prompt("Choose rock, paper, or scissors."); 28 let playerMove = playerChoice[0].toLowerCase(); 29 if (playerMove === computerMove) 30 { 31 alert("It’s a draw."); 32 draws++; 33 } 34 else if (playerMove === "r") 35 { 36 if (computerMove === "p") 37 { 38 alert("Computer picked paper. You lose."); 39 losses++; 40 } 41 else if (computerMove === "s") 42 { 43 alert("Computer picked scissors. You win."); 44 wins++; 45 } 46 } 47 else if (playerMove === "p") 48 { 49 if (computerMove === "s") 50 { 51 alert("Computer picked scissors. You lose."); 52 losses++; 53 } 54 else if (computerMove === "r") 55 { 56 alert("Computer picked rock. You win."); 57 wins++; 58 } 59 } 60 else if (playerMove === "s") 61 { 62 if (computerMove === "r") 63 { 64 alert("Computer picked rock. You lose."); 65 losses++; 66 } 67 else if (computerMove === "p") 68 { 69 alert("Computer picked paper. You win."); 70 wins++; 71 } 72 } 73 } 74 alert("You had " + wins + " wins, " + losses + " losses, and " + draws + " draws."); 75 if (wins > losses) 76 { 77 alert("You win!"); 78 } 79 else if (wins < losses) 80 { 81 alert("You lose!"); 82 } 83 else 84 { 85 alert("It’s a draw!"); 86 } 87 }