Skip to content

Instantly share code, notes, and snippets.

@caesiumtea
Created August 3, 2023 02:11
Show Gist options
  • Save caesiumtea/090142ac618fccc69da543e2459af784 to your computer and use it in GitHub Desktop.
Save caesiumtea/090142ac618fccc69da543e2459af784 to your computer and use it in GitHub Desktop.
Codedex JS Rock-Paper-Scissors
/* Rock Paper Scissors
Solution to this Codedex.io challenge:
https://www.codedex.io/javascript/17-rock-paper-scissors
*/
const rock = 0;
const scissors = 1;
const paper = 2;
let player = rock;
let computer = Math.floor(Math.random() * 3);
if (player === rock) {
console.log("Player picked: Rock");
} else if (player === scissors) {
console.log("Player picked: Scissors");
} else if (player === paper) {
console.log("Player picked: Paper");
} else {
console.log("Something went wrong.");
}
if (computer === rock) {
console.log("Computer picked Rock");
} else if (computer === scissors) {
console.log("Computer picked: Scissors");
} else if (computer === paper) {
console.log("Computer picked: Paper");
} else {
console.log("Something went wrong.");
}
if (player === computer) {
console.log("You tied!");
} else if (player === rock && computer === paper) {
console.log("The computer won!");
} else if (player === rock && computer === scissors) {
console.log("The player won!");
} else if (player === paper && computer === rock) {
console.log("The player won!");
} else if (player === paper && computer === scissors) {
console.log("The computer won!");
} else if (player === scissors && computer === rock) {
console.log("The computer won!");
} else if (player === scissors && computer === paper) {
console.log("The player won!");
} else {
console.log("Something went wrong.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment