Last active
July 10, 2025 09:37
-
-
Save gitdagray/38322a7141f4236e050086e7053febb7 to your computer and use it in GitHub Desktop.
Rock_Paper_Scissors_v1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Your First Interactive Game | |
let playGame = confirm("Shall we play rock, paper, or scissors?"); | |
if (playGame) { | |
//play | |
let playerChoice = prompt("Please enter rock, paper, or scissors."); | |
if (playerChoice) { | |
let playerOne = playerChoice.trim().toLowerCase(); | |
if ( | |
playerOne === "rock" || | |
playerOne === "paper" || | |
playerOne === "scissors" | |
) { | |
let computerChoice = Math.floor(Math.random() * 3 + 1); | |
let computer = | |
computerChoice === 1 | |
? "rock" | |
: computerChoice === 2 | |
? "paper" | |
: "scissors"; | |
let result = | |
playerOne === computer | |
? "Tie game!" | |
: playerOne === "rock" && computer === "paper" | |
? `playerOne: ${playerOne}\nComputer: ${computer}\nComputer wins!` | |
: playerOne === "paper" && computer === "scissors" | |
? `playerOne: ${playerOne}\nComputer: ${computer}\nComputer wins!` | |
: playerOne === "scissors" && computer === "rock" | |
? `playerOne: ${playerOne}\nComputer: ${computer}\nComputer wins!` | |
: `playerOne: ${playerOne}\nComputer: ${computer}\nplayerOne wins!`; | |
alert(result); | |
let playAgain = confirm("Play Again?"); | |
playAgain ? location.reload() : alert("Ok, thanks for playing."); | |
} else { | |
alert("You didn't enter rock, paper, or scissors."); | |
} | |
} else { | |
alert("I guess you changed your mind. Maybe next time."); | |
} | |
} else { | |
alert("Ok, maybe next time."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you