Magic Eight-ball Project

My code is not working and I don’t know why, it doesn’t print any of the cases.

userName = ‘Jane’;
userQuestion = ’ ';
randomNumber = Math.floor(Math.random() * 8);
eightBall = ‘’

if(userName) {
console.log('Hello, ’ + userName);
} else {
console.log(‘Hello’);
};
console.log(userQuestion)

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

Welcome to the forums, @tag3011962216.

Question for you. Recall what you’ve learned about data types.
Is the following statement true or false?

8 === '8'
4 Likes

Can you remember what you’ve learned about data types? Please indicate whether the following statement is true or false.

It’s false as it seems to be the “same” number, however; it’s not the same type as the first one is a number whereas the second option is a string

try this:

let userName = ‘Jane’;
let userQuestion = ’ ';
let randomNumber = Math.floor(Math.random() * 8);
let eightBall = ‘’;

if(userName) {
console.log('Hello, ’ + userName);
} else {
console.log(‘Hello’);
}

console.log(userQuestion)

switch(randomNumber) {
case 0:
console.log(‘It is certain’);
break;
case 1:
console.log(‘It is decidedly so’);
break;
case 2:
console.log(‘Reply hazy, try again’);
break;
case 3:
console.log(‘Cannot predict now’);
break;
case 4:
console.log(‘Do not count on it’);
break;
case 5:
console.log(‘My sources say no’);
break;
case 6:
console.log(‘Outlook not so good’);
break;
case 7:
console.log(‘Signs point to yes’);
break;
// No default case is needed here since all possible values of randomNumber (0 to 7) are covered.
}