Magic 8 Ball Printing randomNumber but not printing strings

I am doing the Magic 8 Ball project in Javascript and am running into a problem. I checked my code with the video help tutorial and even after making adjustments, my code still only logs the random number to the console. It does not perform the switch statement to give a ‘string’ response. I’ve checked and rechecked my switch statements and cases and do not know what I’m doing incorrectly. My code is posted below, please help.
Thank you.

let userName = ('Bradley');
userName ? console.log(`Hello, ${userName}!`) : console.log('Hello!');
let userQuestion = ('Is today Saturday?');
console.log(`${userName} has asked - ${userQuestion}`);
let randomNumber = Math.floor(Math.random() * 8);
console.log(randomNumber);
 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 Magic 8 Ball says, ${eightBall}.`);
}

That is the last line of your code. What is it closing?

Thank you, that was extremely helpful! I understand that I closed the switch function in the wrong place but what I don’t understand in this situation is why does it simply prevent the block from running vs. causing an error code? Are error codes only syntax related? Thank you again for your help.

1 Like

Your code did run without throwing any errors. The problem was that your console.log statement was unreachable because it came after a break statement, but was inside the block of code that the break statement exits. Once control flow entered your switch block, control was passed to the matching case. The variable, eightball, was assigned to a string literal, and control was then sent to the next line after the closing }.

Aside, there’s no need for the parenthesis around your string literals: