Mathematical operations on variables in JavaScript
Mathematical operations can be performed not only on numbers, but on variables too. Let's add, for example, values of two variables:
let a = 1;
let b = 2;
alert(a + b); // shows 3
It is not necessary to display the result of the operation immediately, you can first write it to some variable, and only then display the value of this variable:
let a = 1;
let b = 2;
let c = a + b; // write the sum to the variable c
alert(c); // shows 3
Create the variable a with the value
10 and variable b
with the value 2. Display their sum,
difference, product, and quotient (division result).
Create the variable c with the value
10 and variable d with the value
5. Sum them up and assign the result
to the variable result. Display the
value of the variable result.
Create the variable a with the value
1, variable b with the value
2 and variable c with the value
3. Display their sum.
Create the variable a with the value
10 and variable b with the value
5. Subtract from a the variable
b and assign the result to variable
c.
After, create the variable d, assign
the value 7 to it. Add the variables c
and d, then write the result to the variable
result. Display the value of the
variable result.