-
-
Save eatAsnack/edae56593976e948668e0e12953b3d29 to your computer and use it in GitHub Desktop.
Codecademy export
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
//4 outcomes are: | |
var o1 = 'JavaScript wins!'; | |
var o2 = 'You win!'; | |
var o3 = 'A Draw'; | |
var pcChoice = 0; | |
var userChoice = 0; | |
var pcShows = 'none'; | |
var userShows = 'none'; | |
var outcome = 'none'; | |
console.log('Rock Paper Scissors Game in JavaScript'); | |
while (userChoice < 1 || userChoice > 3 || isNaN(userChoice)) { | |
userChoice = prompt('1 = Rock, 2 = Papper, 3 = Scissors'); userChoice = parseInt(userChoice);} | |
if (userChoice === 1){userShows = 'a Rock';} | |
if (userChoice === 2){userShows = 'Paper';} | |
if (userChoice === 3){userShows = 'Scissors';} | |
while (pcChoice < 1 || pcChoice > 3) { | |
pcChoice = Math.floor(Math.random() * 4);} | |
if (pcChoice === 1){pcShows = 'a Rock';} | |
if (pcChoice === 2){pcShows = 'Paper';} | |
if (pcChoice === 3){pcShows = 'Scissors';} | |
//describe the result | |
console.log('PC throws ' + pcShows + ' as you throw ' + userShows + '!'); | |
//decide winner or draw | |
if ((userChoice === 1) && (pcChoice === 1)){outcome = o3;} | |
if ((userChoice === 1) && (pcChoice === 2)){outcome = o1;} | |
if ((userChoice === 1) && (pcChoice === 3)){outcome = o2;} | |
console.log(' '); | |
console.log(outcome); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment