Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created August 31, 2017 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/946b6355fef6a6f475d013fcb6e2c022 to your computer and use it in GitHub Desktop.
Save codecademydev/946b6355fef6a6f475d013fcb6e2c022 to your computer and use it in GitHub Desktop.
Codecademy export
var userInput = '' ;
uesrInput = userInput.toLowerCase();
const function getUserChoice = userInput =>{
if(userInput === 'rock' || userInput ==='paper' || userInput==='scissors')
return userInput;
else{
console.log('Invalild input');
}
}
function getComputerChoice(){
var randomNumber = Math.floor (Math.random() *3) ;
switch(randomNumber){
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
default:
return 'Invalid choice';
}
}
function determineWinner(userChoice, computerChoice){
if(userChoice === computerChoice)
return ' The game is a tie!';
if(userChoice === 'rock'){
if(computerChoice === 'paper'){
return 'The computer won!';
}
else
return 'You Won!';
}
if(userChoice === 'paper'){
if(computerChoice === 'scissors')
return 'The computer won!';
else
return 'You Won!';
}
if(userChoice === 'scissors'){
if(computerChoice === 'rock'){
return 'The computer won!';
}
else
return 'You Won!';
}
}
const function playGame(){
const userChoice = getUserChoice('scissors';
const computerChoice = getComputerChoice ();
console.log('Your Choice: ' + userChoice);
console.log(' Computer Choice: ' + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
}
playGame();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment