Skip to content

Instantly share code, notes, and snippets.

@eatAsnack
Forked from codecademydev/rockPaperScissors.js
Created March 10, 2017 03:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eatAsnack/edae56593976e948668e0e12953b3d29 to your computer and use it in GitHub Desktop.
Save eatAsnack/edae56593976e948668e0e12953b3d29 to your computer and use it in GitHub Desktop.
Codecademy export
//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