Magic eight ball-no errors but code won't print a result

https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-control-flow/projects/magic-eight-ball-1

Not sure what is wrong. I can not get a result to print. I only have the hello statement and the user question appearing.

let userName='Sal';
userName?
console.log(`Hello, ${userName}!`):
console.log('Hello!');
const userQuestion='Will I die?';
  console.log(`The user asked: ${userQuestion}`);
let randomNumber = Math.floor(Math.random() * 8);
let eightBall='';
switch (randomNumber){
  case 0:
       eightBall='It is certain';
    break;
    case 1:
    eightBall='It is decidedly so';
    break;
     case 2:
    eightBall='Reply hazy try again';
    break;
       case 3:
    eightBall='Cannot predict now';
    break;
     case 4:
    eightBall='Do not count on it';
    break;
    case 5:
    eightBall='My sources say no';
    break;
     case 6:
    eightBall='Outlook not so good';
    break;
     case 7:
    eightBall='Signs point to yes';
    break;
    console.log (`The eight ball answered ${eightBall}`);
    break;
}

the line which is logging the output:

console.log (`The eight ball answered ${eightBall}`);

when is this line executed?

If I add console.log (The eight ball answered ${eightBall}); to every case it works. I didn’t think that was the correct thing to do but… I guess I was wrong.

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

}

Why not simple add it once after the switch statement?

seems to work now:

https://jsbin.com/payitoxoxe/edit?html,js,console

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