const getUserInput = (userInput) =>{
userInput = userInput.toLowerCase();
if(userInput === 'rock' || userInput === 'paper' || userInput === 'scissors'){
return userInput;
}
else{
console.log("Wrong Input Sir! pick between rock ,paper and scissors");
}
}
// console.log(getUserInput('rck'));
const getComputerChoice = () =>{
const randomChoice = Math.floor(Math.random() * 3);
switch (randomChoice) {
case 0:
return 'rock'
break;
case 1:
return 'paper'
break;
case 2:
return 'scissors'
break;
}
}
const determineWinner = (userChoice, ComputerChoice) =>{
if(userChoice === ComputerChoice){
return 'Thats Tie Gentlemens';
}
if(userChoice === 'rock'){
if(ComputerChoice === 'paper'){
return 'Computer Won';
}else{
return 'User won';
}
}
if(userChoice === 'paper'){
if(ComputerChoice === 'scissors'){
return 'Computer won';
}else{
return 'User Won';
}
}
if(userChoice === 'scissors'){
if(ComputerChoice === 'rock'){
return 'Computer won';
}else{
return 'User Won';
}
}
};
const Playgame = () =>{
const userChoice = getUserInput('rock');
const ComputerChoice = getComputerChoice();
console.log('User Input :-',userChoice);
console.log('Computer Input :-',ComputerChoice);
console.log(determineWinner(userChoice,ComputerChoice));
}
Playgame();