Magic Eight Ball

Hi folks,
Please give me a hint. My code for Magic Eight Ball project doesn’t work

Here’s my code :

let userName = "Sandra";

userName ? 
console.log(`Hello, ${userName}`)

: console.log('Hello!');

let userQuestion = "Please answer me";

console.log(`The user asked ${userQuestion}`);

let 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 = 'Reply 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(`The eight bal answered : ${eightball}`);


I don’t get any errors when I run the code. Only 1 answer, even if i run it many times. It displays :

Hello, Sandra
The user asked Please answer me

You nested your console.log within your switch statement? if you want to log every time, you should move your .log() to outside/after the switch statement

1 Like

Thanks stetim94, it worked !

also I had typed eightball at the end, instead of eightBall … corrected that too …

It’s such a good feeling when the issue is sorted ! I know this is only the beginning but it has been 35 years since I learnt C++ and I couldn’t remember a thing ! Only the coders will understand the joy of coding ! I love Codecademy !

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.