Magic Eight Ball - I can't get String Interpolation to work

var userName = 'Robbie';

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

const userQuestion = 'Will I win the lottery?'; console.log(userName + ' asked: ' + userQuestion);

const randomNumber = Math.floor(Math.random() * 8);

let eightBall = '';

switch (randomNumber) {
  case 0:
    eightBall = 'Yes';
    break;
  case 1:
    eightBall = 'No';
    break;  
	case 2:
    eightBall = 'Maybe';
    break;  
  case 3:
    eightBall = 'Probably';
    break;  
  case 4:
    eightBall = 'Probably not';
    break;  
  case 5:
    eightBall = 'Doubtful';
    break;  
  case 6:
    eightBall = 'No way';
    break;  
  case 7:
    eightBall = 'Of course not';
    break;  
}

console.log('The eight ball answered: ' + eightBall);

What am I doing wrong?

It appears you've used single quotes ' instead of back tics `
On most keyboards the back tic is located just to the left of the 1 key. With back tics, your code will look like this:
userName ? console.log(`Hello ${userName}!`) : console.log('Hello!');
//Output: Hello Robbie!

Hope this helps!

1 Like