SyntaxError: expected expression, got keyword 'else'


#1

SyntaxError: expected expression, got keyword 'else'

If (computerChoice <= 0.33)
{computerChoice = "rock";}
else if (computerChoice < 0.67)
{computerChoice = "paper"; }
else
{computerChoice = "scissors"; }

I would appreciate it if some one could pint out what I am missing here. thanks

-Update: I used the above spacing for (my) readability, here is the more standard one, which changes the error message to:
SyntaxError: missing before statement


If (computerChoice <= 0.33) {
computerChoice = "rock";
} else if (computerChoice < 0.67) {
computerChoice = "paper";
} else { computerChoice = "scissors";
}


Again, thank to anyone who can help


#2

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)


#3

Thank you for checking my code and your response.
I have checked the spelling numerous, counted the round and curly brackets pairs. I can not see which semicolon is missing. I have one after each "then" action, but none after a condition and nine after a closed curly brackets, ie 3 "then" action = 3 semicolons.

Can you please point out what I am missing?
Thank you.

Don't worry, I worked around it.


#4

@taxsyn We have answered your question here: https://www.codeforx.com/questions/syntaxerror-expected-expression-got-keyword-else

You can ask questions at codeforx.com, and we aim to answer quickly


#5

why wouldn't you need the and (&&) operator?

example:

if (computerChoice <= 0.33) {
console.log("rock");
}
else if (computerChoice >= 0.34 && computerChoice <= 0.66) {
console.log("paper");
}
else {
console.log("scissors");
}


#6

Maybe just because you need to use lowercase in "if".


#8

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