In the Rock, Paper and Scissor project in the Function.
const getUserChoice = userInput =>{
userInput = userInput.toLowerCase();
if(userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’){
return userInput;
} else{
console.log(`Invalid Input`)
}
}
const getComputerChoice = () =>{
const randomNumber = Math.floor(Math.random() * 3);
switch(randomNumber) {
case 0:
return 'rock';
break;
case 1:
return 'paper';
break;
case 2:
return 'Scissors';
break;
}
}
const determinesWinner = (userChoice , computerChoice) =>{
if(userChoice === computerChoice){
return 'The game was a TIE!';
} else if(userChoice === ‘rock’){
if(computerChoice === 'paper'){
return 'Computer Won!'
} else {
return 'User Won!'
}
} else if(userChoice === ‘paper’){
if(computerChoice === 'rock'){
return 'User Won!';
} else {
return 'Computer Won!';
}
} else if(userChoice === ‘scissors’){
if(computerChoice ==='rock'){
return 'Computer Won!';
} else {
return 'User Won!';
}
}
}
[quote=“786karanbadhwar, post:1, topic:553813, full:true”]
In the Rock, Paper and Scissor project in the Function.
const getUserChoice = userInput =>{
userInput = userInput.toLowerCase();
if(userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’){
return userInput;
} else{
console.log(`Invalid Input`)
}
}
const getComputerChoice = () =>{
const randomNumber = Math.floor(Math.random() * 3);
switch(randomNumber) {
case 0:
return 'rock';
break;
case 1:
return 'paper';
break;
case 2:
return 'Scissors';
break;
}
}
const determinesWinner = (userChoice , computerChoice) =>{
if(userChoice === computerChoice){
return 'The game was a TIE!';
} else if(userChoice === ‘rock’){
if(computerChoice === 'paper'){
return 'Computer Won!'
} else {
return 'User Won!'
}
} else if(userChoice === ‘paper’){
if(computerChoice === 'rock'){
return 'User Won!';
} else {
return 'Computer Won!';
}
} else if(userChoice === ‘scissors’){
if(computerChoice ==='rock'){
return 'Computer Won!';
} else {
return 'User Won!';
}
}
}
It is working good if i do this way
/*function playGame(){
const userChoice = getUserChoice(‘rock’);
console.log(User threw: ${userChoice}
);
const computerChoice = getComputerChoice();
console.log(Computer threw: ${computerChoice}
);
console.log(determinesWinner(userChoice, computerChoice));
}
playGame();*/
but why it is not working if i do this way
console.log(determinesWinner(console.log(getUserChoice(‘rock’)), console.log(getComputerChoice())));