Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created August 22, 2023 06:17
Show Gist options
  • Save codecademydev/f2eda93aea621b91bc24952e802268b4 to your computer and use it in GitHub Desktop.
Save codecademydev/f2eda93aea621b91bc24952e802268b4 to your computer and use it in GitHub Desktop.
Codecademy export
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if(userInput === 'rock' || userInput ==='paper' || userInput === 'scissors' || userInput === 'bomb'){
return userInput;
}else{console.log('Error!')}
}
const getComputerChoice = () => {
randomNumber = Math.floor(Math.random() * 3)
switch(randomNumber){
case 0:
return 'rock'
break;
case 1:
return 'paper'
break;
case 2:
return 'scissors'
break;
}
};
const determineWinner = (userChoice,computerChoice) =>{
if(userChoice === computerChoice){
return console.log('the game is a tie ! ')}
if(userChoice === 'rock'){
if(computerChoice === 'paper'){
return 'The computer won!'
}else{
return 'You win!'
}
}
if(userChoice === 'paper'){
if(computerChoice === 'scissors'){
return 'Computer win'
}else{
return 'You win'
}
}
if(userChoice === 'scissors'){
if(computerChoice === 'rock'){
return 'Computer win !'
}else{
return'You win !'
}
}
if(userChoice === 'bomb'){
return 'congratulation you win'
}
};
const playGame =()=>{
const samir = getUserChoice('bomb');
const computer = getComputerChoice();
console.log('You threw:' + samir);
console.log(`The computer threw: ${computer}`);
console.log(determineWinner(samir,computer))
};
playGame();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment