Created
August 3, 2023 02:11
-
-
Save caesiumtea/090142ac618fccc69da543e2459af784 to your computer and use it in GitHub Desktop.
Codedex JS Rock-Paper-Scissors
This file contains 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
/* 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