Syntax error, where did i go wrong?

https://www.codecademy.com/courses/introduction-to-javascript/projects/magic-eight-ball-1

var userName = “”;
userName?
console.log(“Hello Jane!”):
console.log(“Hello!”);
const userQuestion = “Will i be rich?”;
console.log(The user asked: ${userQuestion});
var randomNumber = Math.floor(Math.random() * 8);
let eightBall = “”;

if (randomNumber === 0); {
console.log(“It is certain”);
} else if (randomNumber === 1); {
console.log(“It is decidedly so”);
} else if (randomNumber === 2);{
console.log(“Reply hazy try again”);
} else if (randomNumber === 3);{
console.log(“Cannot predict now”);
} else if (randomNumber === 4);{
console.log(“Do not count on it”);
} else if (randomNumber === 5);{
console.log(“My sources say no”);
} else if (randomNumber = 6);{
console.log(“Outlook not so good”);
} else if (randomNumber = 7);{
console.log(“Signs point to yes”);
} else (randomNumber = 8); {
console.log(“One in a million”);
}
console.log(The eight ball answered: ${eightBall});

says in the console:
} else if (randomNumber === 1); {
^^^^
SyntaxError: Unexpected token else

I would use switch here.

as for your syntax error, that is caused by incorrect usage of semi-colons.

if (randomNumber === 0); {, the semi-colon in this line is interrupting your if condition. And given else if can only be after an if or another else if, you get an syntax error

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