so I’m getting a syntax error (pasted below), I cannot figure out what I’m doing wrong. I’ve watched the walkthrough video and cannot figure out where the deviation from the video syntax are.
const getUserChoice = (userInput) => {
userInput = userInput.toLowerCase();
if (getUserChoice === ‘rock’ || getUserChoice === ‘paper’ || getUserChoice === ‘scissors’);{
return userInput;
} else {
console.log(‘Error, please type Rock, Paper, or Scissors’);
}
};
console.log(getUserChoice(‘paper’));
/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:5
} 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) Welcome to the Get Help category!
This is where you can ask questions about your code. Some important things to remember when posting in this category
The thing to understand here can broken into two parts.
End-of-statement token, the semi-colon. This terminates parsing and passes the parsed code (from the start of the line) to the interpreter. The if body is never parsed, so doesn’t exist in that phase of execution.
Block containment, the {} that accompanies a construct or function. Blocks execute immediately which in this case means that there is no condition allowing or disallowing it. It just runs.
You are not alone. It’s one of the most common beginner errors we see. Use of semi-colons is a question that comes up often.The real truth is that JS actually inserts them for us so we don’t technically need them, ever, in our code. It is nonetheless an important syntax to understand thoroughly if you wish to go into C, PHP, Java, et al. JS, not such a big deal.
It’s important to consider line parsing. JS parses line by line, for the most part. A line break is akin to an end-of-statement.
Ping us back if you want to go into greater detail of when and when not to use ;.
sure I think I’d like more info… but I’ll be honest the statement about line parsing might as well be written in a different language cause I have no clue what that means.