const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if(userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
return userInput;
} else {
console.log("Type Rock, Paper or Scissors");
}
}
//console.log(getUserChoice('Paper'));
const getComputerChoice = () => {
let number = Math.floor(Math.random()*3);
//return number;
// console.log(number);
switch(number) {
case 0 : return 'rock';
break;
case 1 : return 'paper';
break;
default : return 'scissors';
break;
}
}
console.log(`Computer Choice ${getComputerChoice()}`);
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice){
return 'Game is tie';
}else if (userChoice === 'rock' && computerChoice === 'paper') {
return 'Computer won';
} else if (userChoice === 'paper' && computerChoice === 'scissors') {
return 'Computer won';
} else if (userChoice === 'scissors' && computerChoice === 'rock') {
return 'Computer won';
} else {
return 'User won';
}
}
console.log(determineWinner('paper', 'scissors'));
console.log(determineWinner('paper', 'paper'));
console.log(determineWinner('paper', 'rock'));
console.log(determineWinner('paper', getComputerChoice()));
Computer Choice rock
Computer won
Game is tie
User won
Game is tie
the last result should User won but it shown user won, why does it happend.