Magic Eight Ball

I have worked trhough the Eight Ball excercise and finally got the else if statement to work. However, when the random number is seven, it won’t print the answer to the console.

let randomNumber = Math.floor(Math.random() * 8);

let eightBall = "";

 if (randomNumber === 0) {

  eightBall = "It is certain";

} else if (randomNumber === 1) {

  eightBall = "It is decidedly so";

} else if (randomNumber === 2) {

  eightBall = "Reply hazy try again";

} else if (randomNumber === 3) {

  eightBall = "Cannot predict now";

} else if (randomNumber === 4) {

  eightBall = "Do not count on it";

} else if (randomNumber === 5) {

  eightBall = "My sources say no";

} else if (randomNumber === 6) {

  eightBall = "Outlook not so good";

} else {

  eigthball = "Signs point to yes";


console.log(`The number is ${randomNumber}: ${eightBall}`);

It will print The number is 7: but nothing more.
I thought you had to close the statement with and else and that would be the leftover value. Is that correct? Why does it not print the entire console.log?

Another question I have here is, what is the difference between = and ===? This was my original mistake in this project, but I haven’t fully understood this yet. Note English is not my first language.

Thank you for your help.

Hi @sheisariver
Your code is fine and the assignment in the else statement will work once you removed the spelling mistake.
= is an assignment operator. With the assignment operator, you set a value to a variable. With == and === you are comparing. With == you compare values and with === you compare values and types. E.g.

'1' == 1 // true, because the value is 1 in both cases
'1' === 1 // false, because the value is 1, but the type of the first is string and the type of the second is number
1 Like

Thank you! I think I got it now.