Rock paper scissors syntax error , please help


#1

I’ve been staring at this for a couple days, reading other peoples questions and answers, and testing different things. any help would be appreciated. I can’t see the issue. I tried different bracketing to see if I had bracketed incorrectly or incompletely and changing to else if’s instead of just else
thanks for looking with me.

ok heres the error message:

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:6
} else {
^^^^
SyntaxError: Unexpected token else
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)

and heres my code:

const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
{if (userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’);
{
return userInput;
} else {
console.log(‘Error!’);
}
}
const getComputerChoice = randomNumber =>
{ randomNumber = Math.floor(Math.random() * 3);
{switch (randomNumber) {
case 0:
return ‘rock’;
case 1:
return ‘paper’;
case 2:
return ‘scissors’;
}
}
}
function determineWinner (userChoice, computerChoice) {
if (userChoice === computerChoice) {
return ‘game was a tie!’;
}
{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 =
getUserChoice(‘paper’);
const computerChoice = getComputerChoice();
console.log(you threw: ${userChoice});
console.log(the computer threw: ${computerChoice});
console.log(determineWinner(userChoice, computerChoice));
};
playGame();


#2

the problems isn’t with your brackets, its with your semi-colons. Or rather, semi-colon. Having a semi-colon at the wrong spot can have disastrous consequences as you are currently experiencing.


#3

thank you, I will go back through


#4

stetim94:

I think I’ve straightened out that issue, now if I have experienced a different issue that I can’t track can I repost here with a reply or start a new query?


#5

depends, if its the same exercise, i think its okay to post in the same topic


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.