Help w/ Magic Eightball Control Flows

I entered my code for the Magic 8ball, even followed through the “get help” tutorial step by step or so i thought. Can anyone tell me what I’m doing wrong?

also, it doesn’t generate the name entered it just puts $username

My code:

let userName = 'India';
userName ? console.log('Hello, $userName'): console.log('Hello!');
let userQuestion = 'Will I be a Top Chef?';
console.log( `India asked : ${userQuestion}`)
let randomNumber = Math.floor(Math.random() * 7);
let eightBall = '';

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

compare how you have used template literals on line 2 vs line 4. there’s inconsistency in the way you’re using them. see if you can spot the bug there. clue is in your own code :wink:

review the last line of your code. you have a bug there.

Also bugs in each case statement. randomNumber is a number :slightly_smiling_face:

1 Like

console.log() will take any expression, including a ternary…

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