

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
click for more info
Not enough gems
Cost: 6 gems
1: Learn JavaScript
incomplete
2: Basic Variables
incomplete
3: let and const
incomplete
4: Why JavaScript?
incomplete
5: Comments
incomplete
6: Numbers in JS
incomplete
7: Numbers Review
incomplete
8: Increment and Decrement
incomplete
9: Undefined vs. Undeclared
incomplete
10: Null vs. Undefined
incomplete
11: Dynamic and Weak
incomplete
12: Same Line Declarations
incomplete
13: JavaScript's Speed
incomplete
14: Strings
incomplete
15: Template Literals
incomplete
16: Java vs. JavaScript
incomplete
17: Semi-Colons in JS
incomplete
18: String Encoding
incomplete
19: Camel Case in JS
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
In JavaScript, template literals are a fantastic way to interpolate dynamic values into a string. They're JavaScript's version of Python's f-strings. For example:
const shadeOfRed = 101;
console.log(`The shade is ${shadeOfRed}`);
// The shade is 101
Template literals must start and end with a backtick, and anything inside of the dollar-sign bracket enclosure is automatically cast to a string.
You aren't limited to just variable names inside the ${}. You can actually write valid JavaScript code directly inside them.
This means you can do math, change text styles, or run logic checks right inside the string.
const price = 2.5;
const quantity = 3;
const item = "coffee";
console.log(`Total: $${price * quantity}`);
// Total: $7.5
console.log(`I need ${item.toUpperCase()}`);
// I need COFFEE
Using the template literals and string formatting illustrated above, create a new variable msg and assign it the string:
Hi NAME, your open rate is OPENRATE percent
NAME with the variable name.OPENRATE with the variable openRate.