Shorthand operations in JavaScript
For such operations, when to the variable
its current value plus something else is written,
there is a special shortened syntax.
This syntax uses the special operator +=
instead of the normal assignment.
Let's look at an example:
let num = 1;
num += 3; // equivalent to num = num + 3;
There are similar operators for other mathematical operations:
let num = 2;
num -= 3; // equivalent to num = num - 3;
let num = 2;
num *= 3; // equivalent to num = num * 3;
let num = 2;
num /= 3; // equivalent to num = num / 3;
Modify this code to use the above described shorthand operations:
let num = 47;
num = num + 7;
num = num - 18;
num = num * 10;
num = num / 15;
alert(num);