Magic Eight Ball will not print userName or UserQuestion

My code will not print the userName or userQuestion. I have tried it various ways. I even typed it exactly as the video resolution and it still would not fix. Can any of you tell me what I am doing wrong?

let userName = "Lissa";
userName ? console.log('Hello, $userName') : console.log('Hello!');
// I have also tried this line of code as ('Hello, ${userName}!')
let userQuestion ='Can I have cake for breakfast?';
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(eightBall);

To use template literals:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

the strings needs to be enclosed in backticks/grave accent.

1 Like

Ok i’ve updated it to this:

let userName = “Lissa”;
userName ? console.log(‘Hello, {userName}!') : console.log('Hello!'); let userQuestion ='Can I have cake for breakfast?'; 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(eightBall);

and the log still only showed:


Hello, {userName} The user asked:{userQuestion}
Outlook not so good

wait i just fixed it! this whole time I have been using Apostrophe’s instead of backticks on the template literal