There is something wrong with my syntax with the following code. The red indicators state it has something to do with the else and the brackets. Can anyone find my mistake?
function getUserChoice(){
var UserInput= prompt(‘Rock, Paper, or Scissors?’);
userInput = userInput.toLowerCase();
if (userInput === ‘rock’ || userInput === ‘paper’|| userInput === ‘scissors’)
return userInput;
} else {
console.log(‘Error!’);
}
So I figured out that the return userInput line had to be directly under the prompt line and it works properly. But I ran into another problem with the rest of my code. The output doesn’t determine a winner. This is what I have:
function determineWinner(userChoice, computerChoice){
if(userChoice===computerChoice){
return 'The game is a tie!';
} if(userChoice==='Paper'){
if(computerChoice==='Scissors')
{
return'The computer won!';
} else {
return 'You won!';
if(userChoice==='Scissors'){
if (computerChoice==='Rock'){
return 'The computer won!';
}else {
return 'You won!';
}
}
}
}
}
function playGame(){
var userChoice= getUserChoice();
var computerChoice= getComputerChoice();
console.log('You chose: ' + userChoice);
console.log( 'The Computer Chose: ' + computerChoice);
determineWinner(userChoice,computerChoice);
}
playGame();