Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created July 19, 2020 10:28
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/0d908f809e40d9dc8d433288ed5c33b4 to your computer and use it in GitHub Desktop.
Save codecademydev/0d908f809e40d9dc8d433288ed5c33b4 to your computer and use it in GitHub Desktop.
Codecademy export
const getUserChoice= userInput=>{
userInput=userInput.toLowerCase();
if(userInput==='rock' || userInput==='scissors'|| userInput==='paper'){return userInput} else{ console.log('invalid input :( try rock, paper or scissors');}
}
const getComputerChoice=()=> {
let number=Math.floor(Math.random()* 3)
switch (number) {
case 0 :
return 'rock';
case 1 :
return 'paper';
case 2 :
return 'scissors';
}
}
const determineWinner=(userChoice, computerChoice)=>{
if (userChoice===computerChoice){
return 'It is tie';
}
if (userChoice==='rock'){
if(computerChoice==='paper'){
return 'You were defeated by the computer :(';
}else{
return 'Hurray! you won against the computer!';
}
if (userChoice==='paper'){
if(computerChoice==='scissors'){
return 'You were defeated by the computer :(';
}else{
return 'Hurray! you won against the computer!';
}
}
if (userChoice==='scissors'){
if(computerChoice==='rock'){
return 'You were defeated by the computer :(';
} else {
return 'Hurray! you won against the computer!';
}
}
}
}
console.log(determineWinner('scissors', 'rock'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment