8 Ball Project

I’m currently completing the 8 Ball and Race Day projects and in both projects, I run into the issue where this line of code

console.log('User asked: ${userQuestion} ')does not print the value of the variable but instead prints as is in string form.

Why is this happening?

let userName = 'Jonathon'; userName ? console.log('Hello, ${userName}!') : console.log('Hello!'); const userQuestion = 'Will I find $100 today?'; console.log('The user asked: ${userQuestion}'); const 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; default: eightBall='invalid'; }*/ if (randomNumber===0){eightBall='It is certain'; }else if(randomNumber===1){eightBall='It is decidedly so'; }else if(randomNumber===2){eightBall='Reply hazy try again'; }else if(randomNumber===3){eightBall='Cannot predict now'; }else if(randomNumber===4){eightBall='Do not count on it'; }else if(randomNumber===5){eightBall='My sources say no'; }else if(randomNumber===6){eightBall='Outlook not so good'; }else if(randomNumber===7){eightBall='Signs point to yes'; }else{console.log('ERROR 404');} console.log('The eight ball answered: ${eightBall}');

Template Literals are made using backtick characters ` and not single quotes '. Backticks are normally in the top left corner keys in your keyboard.
Only template literals allow the replacement of variables within the text.

Single quotes ’ and double quotes " create regular strings. Variables need to be concatenated using the “string” + variableName + “string” format

2 Likes
let userName = 'Jonathon';

// Using string concatenation
console.log('Hello ' + userName + '!');

// Using template literals
console.log(`Hello ${userName}!`);
1 Like

holy ■■■■ yes :sweat_smile:
thank you