Magic Eight Ball - String Interpolation

Hi I’m struggling with string interpolation on the Magic Eight Ball project.

My code is below. Rather than printing the string for the variable within {}, the code reader is printing what is actually typed. Instead of 'Will I die this year?' console logs {userQuestion}

ok so when I posted this it’s not registering the dollar sign for some reason…? I guess part of my problem?

let userName = ‘’;

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

const userQuestion = ‘Will I die this year?’;

console.log(‘The user asked: ${userQuestion}’);

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

let eightBall = ‘’

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

1 Like

Hi! The problem is that you used quotation marks instead of the ticks.

console.log(‘The user asked: ${userQuestion}’);

Instead of

console.log(`The user asked: ${userQuestion}`);
1 Like

I had the same problem!! Thank you - but why do the quotations work on some strings, but not on these? Is it specifically because it is string interpolation?

Yep. If you’re using string concatenation or just writing a regular string, you have to use quotation marks.

1 Like