Eight Ball



I am stuck on the project were i create an eight ball with code.

It doesn’t print out what the eightball says about my question.


var userQuestion = ‘Am I a potato?’;
var randomNumber = Math.floor(Math.random() * 7);
var eightBall = ‘’;
switch (eightBall) {
case ‘0’:
eightBall = ‘It is certain’;
case ‘1’:
eightBall = ‘It is decidedly so’;
case ‘2’:
eightBall = ‘Reply hazy try again’;
case ‘3’:
eightBall = ‘Cannot predict now’;
case ‘4’:
eightBall = ‘Don’t count on it’;
case ‘5’:
eightBall = ‘My sorces say no’;
case ‘6’:
eightBall = ‘Outlook not os good’;
case ‘7’:
eightBall = ‘Signs point to yes’;
console.log('The user asked: ’ + userQuestion);
console.log('The eight ball answered: ’ + eightBall);


eightBall = 'Don't count on it';

Error comes from this line.If you need a ' in string then use "" for that string.for example:

"i'm user"

now look at here

switch (eightBall)

you used eightBall for switch case.but the value of eightBall is always an empty string. So you’ll not get any expected results. Do something so that the value of eightBall can be change randomly between 0 to 7.

now if you want to return a number between 0 (inclusive) to 7 (inclusive) then you need to use

Math.random() * 8

because Math.random() returns a number between 0 (inclusive) to 1 (exclusive).


Your code is screening for strings but since you are looking for var randomNumber which is a number despite being random it should be case 0: instead of case ‘0’: .