Hello All
I could really use your help. When I run Rock, Paper, Scissors
the console.log returns
Undefined for userInput and the determineWinner.
I do not receive an error message.
Thank you for your help
Here’s my code:
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput==='rock'|| userInput==='paper' || userInput==='scissors' || userInput==='bomb') {
} else
{ console.log('Error...Please enter rock, paper, or scissors')
}
}
//Computer Choice random # & Switch statement
const getComputerChoice = () => {
const randomNumber = Math.floor(Math.random()*3)
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
}
};
// Step 6 (Turned off)
/*
console.log(getComputerChoice());
console.log(getComputerChoice());
console.log(getComputerChoice());
*/
//Step 7 Determine Winner
const determineWinner =(userChoice, computerChoice) => {
if (userChoice===computerChoice) {
return "We have a draw";
}
if (userChoice==='rock') {
if (computerChoice==='paper') {
return "Computer Wins!";
} else {
return "You Win!";
}
}
if (userChoice === 'paper'){
if (computerChoice === 'scissors'){
return "Computer Wins!";
} else {
return "You Win!";
}
}
if (userChoice === 'scissors'){
if (computerChoice === 'rock') {
return "Computer Wins!";
} else {
return "You Win!";
}
}
if (userChoice === 'bomb'){
return 'You Win--Nice play';
}
};
//Step 11 Testing
/*
console.log(determineWinner('rock', 'scissors'))
console.log(determineWinner('scissors', 'rock'))
console.log(determineWinner('rock', 'rock'))
*/
//Step 12
const playGame = () => {
const userChoice = getUserChoice('paper');
const computerChoice = getComputerChoice();
console.log('You threw: '+ userChoice);
console.log('The computer threw: '+ computerChoice);
console.log(determineWinner(userChoice, computerChoice));
};
playGame()