Magic eightball only prints default

Here is my code. Im not sure what could be wrong at this point because i’ve been stuck for over an hour and a half now.
let userName = (‘levi’);
if (userName === ‘levi’)
console.log(‘Hello Levi!’);
let userQuestion = (‘Am I good at coding?’)
if (userQuestion === ‘Am I good at coding?’)
console.log(‘Am I good at coding?’)
const randomNumber = Math.floor(Math.random() * 8);
let eightBall = ‘’;
switch (randomNumber) {
case ‘0’ :
eightBall =(‘It is certain’)
case ‘1’ :
eightBall =(‘it is decidedly so’)
case ‘2’ :
eightBall =(‘really hazy try again’)
case ‘3’ :
eightBall = (‘Cannot predict now’)
case ‘4’ :
eightBall =(‘do not count on it’)
case ‘5’ :
eightBall =(‘my sources say no’)
case ‘6’ :
eightBall =(‘outlook not so good’)
case ‘7’ :
eightBall =(‘signs point to yes’)
console.log(‘no eigthBall found!’)
anybody know what’s wrong with this?

Your switch statement is checking randomNumber but your cases provide the strings of those numbers.

Do we really need all those brackets?

Isn’t, let userName = 'levi'; delimited enough?

1 Like

I’m sorry, I don’t understand what that means.

What @zeke0 is saying is that the data type of the value stored in randomNumber is ‘number’. Your cases are looking for a value of the data type ‘string’ (case ‘1’):

console.log(typeof 1 === 'number') // true 
console.log(typeof '1' === 'number') // false 
console.log(typeof '1' === 'string') // true 

I’m sorry I still don’t understand. What is wrong with my code or what is missing from it?

Why did you put the numbers in your cases in quote marks?

1 Like