From 0926d5a0fce1e8a4dccac092fe3ab2fe86207eba Mon Sep 17 00:00:00 2001 From: nodemixaholic Date: Sun, 10 Mar 2024 20:36:48 +0000 Subject: [PATCH] Advance game logic to be player vs bot instead of bot vs bot. --- rps.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/rps.js b/rps.js index 00c3610..08ce8be 100644 --- a/rps.js +++ b/rps.js @@ -14,30 +14,24 @@ function playRPS() { player1Choice = "Scissors"; } - if (Math.abs(player2 - 1) < Math.abs(player2 - 2) && Math.abs(player2 - 1) < Math.abs(player2 - 3)) { - player2Choice = "Rock"; - } else if (Math.abs(player2 - 2) < Math.abs(player2 - 1) && Math.abs(player2 - 2) < Math.abs(player2 - 3)) { - player2Choice = "Paper"; - } else { - player2Choice = "Scissors"; - } + player2Choice = prompt("Rock, Paper, or Scissors?") // Determine the winner based on game logic let winner; if (player1Choice === player2Choice) { winner = "Tie"; } else if (player1Choice === "Rock") { - winner = player2Choice === "Scissors" ? "Player 1" : "Player 2"; + winner = player2Choice === "Scissors" ? "Bot" : "Player"; } else if (player1Choice === "Paper") { - winner = player2Choice === "Rock" ? "Player 1" : "Player 2"; + winner = player2Choice === "Rock" ? "Bot" : "Player"; } else { // player1Choice === "Scissors" - winner = player2Choice === "Paper" ? "Player 1" : "Player 2"; + winner = player2Choice === "Paper" ? "Bot" : "Player"; } // Print the results - console.log(`Player 1: ${player1Choice}`); - console.log(`Player 2: ${player2Choice}`); - console.log(`Winner: ${winner}`); + alert(`Bot: ${player1Choice} + Player: ${player2Choice} + Winner: ${winner}`); } // Play the game twice (once per player)