Problem with conditionals working along random numbers

Hello everyone!

I am completing the project regarding conditionals in the JavaScript course (https://www.codecademy.com/courses/introduction-to-javascript/projects/magic-eight-ball-1)

I am having huge problems getting eightBall to display the messages I’d like it to.
I generate a randomNumber, and this works: I checked by logging randomNumber to the console.
However, eightBall does not display any messages whenever randomNumber = 0 || randonNumber > 2 is passed into it.

This is my code:

let userName = ‘Jane’;
userName ? console.log(`Hello, \${userName}!`) : console.log(‘Hello!’);
let userQuestion = ‘Will I fall in love?’;
console.log(`The user asked: \${userQuestion}`);
let randomNumber = Math.floor(Math.random() * 8 );
console.log(randomNumber);
let eightBall = ‘’;

switch(randomNumber) {
case 0:
eightball = ‘It is certain’;
break;
case 1:
eightBall = ‘It is decidedly so’;
break;
case 2:
eightBall = ‘Reply hazy try again’;
break;
case 3:
eightball = ‘Cannot predict now’;
break;
case 4:
eightball = ‘Do not count on it’;
break;
case 5:
eightball = ‘My sources say no’;
break;
case 6:
eightball = ‘Outlook not so good’;
break;
case 7:
eightball = ‘Signs point to yes’;
break;
}
console.log(eightBall);

Hey Gabriele, welcome to the forums!

You might want to double check for slight typos.

You currently have eightball and eightBall, and trying to log eightBall.

Well, that was an easy fix!
And also an embarrassing one. I manually typed the first two cases, then quickly realised that I could have made it quicker by copying-pasting it.
Little did I know I had copied one with the wrong format…

Thanks a lot! That small thing was driving me crazy.
I guess I learnt the lesson: always check spelling first!

1 Like