Numbers and text
JavaScript does arithmetic the way you expect:
| Symbol | Meaning | Example | Result |
|---|---|---|---|
+ |
add | 7 + 3 |
10 |
- |
subtract | 7 - 3 |
4 |
* |
multiply | 7 * 3 |
21 |
/ |
divide | 7 / 2 |
3.5 |
% |
remainder | 7 % 3 |
1 |
Brackets work as in maths: (2 + 3) * 4 is 20.
Building sentences with + gets messy. Template literals are neater. They use backticks (`, usually on the key left of 1) and put values inside ${ }:
const item = "bread";
const price = 1.5;
console.log(`One ${item} costs ${price} dollars.`);
// One bread costs 1.5 dollars.
Anything inside ${ } is worked out first, so you can even write ${price * 2}.
Your task
The starter has a price and a quantity.
- Create
total: the price times the quantity. - Create
perPerson: the total shared between 4 people. - Print exactly
3 meals cost 750, so 187.5 eachusing a template literal and your variables.