Coding for All
Lesson 4: Doing Maths
Doing Maths Try all four maths operators.
1console.log(7 + 3);
2console.log(7 - 3);
3console.log(7 * 3);
4console.log(7 / 2);
Terminal
$ node main.js
10
4
21
3.5
Every line, explained
console.log(7 + 3);
+ adds two numbers together.
console.log(7 - 3);
- subtracts the right number from the left one.
console.log(7 * 3);
* means multiply: there is no × key on a keyboard, so programmers use the asterisk.
console.log(7 / 2);
/ means divide. 7 / 2 gives 3.5; JavaScript happily gives decimal answers.