rock paper scissors

PHOTO EMBED

Fri Jun 24 2022 20:09:54 GMT+0000 (Coordinated Universal Time)

Saved by @cruz #javascript

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';
  case 1:
    return 'paper';
    case 2:
    return 'scissors';
  
}
}; 


const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice){
  return 'This game is a tie';
}
if (userChoice === 'rock'){
  if (computerChoice === 'paper'){
    return 'Looks like you lost!';
  } else{
    return 'Congrats you won!!!';
  }
}
if (userChoice === 'paper'){
  if( computerChoice === 'scissors'){
    return 'Looks like you lost!';
  } else{
    return 'Congrats you won!!!';
  }
}
if (userChoice === 'scissors'){
  if (computerChoice === 'rock'){
    return 'Looks like you lost!';
  }else{
    return 'Congrats you won';
  }
}
if (userChoice === 'bomb'){
  return 'You got the answers Sway!!! You Win!!'
}
};

console.log(determineWinner('rock','scissors'));
console.log(determineWinner('rock','paper'));
console.log(determineWinner('paper','paper'));
console.log(determineWinner('bomb','paper'));



const playGame =() =>{
const userChoice = getUserChoice('rock');
const computerChoice = getComputerChoice();
console.log(`You threw: ${userChoice}`);
console.log(`The Computer threw: ${computerChoice}`);

console.log(determineWinner(userChoice,computerChoice))
};

playGame();
content_copyCOPY