Operators

You can apply mathematic operations to numbers using some basic operators like:

  • Addition: c = a + b
  • Subtraction: c = a - b
  • Multiplication: c = a * b
  • Division: c = a / b

You can use parentheses just like in math to separate and group expressions: c = (a / b) + d

{% exercise %}
Create a variable x equal to the sum of a and b divided by c and finally multiplied by d.
{% initial %}
var a = 2034547;
var b = 1.567;
var c = 6758.768;
var d = 45084;

var x =
{% solution %}
var a = 2034547;
var b = 1.567;
var c = 6758.768;
var d = 45084;

var x = ((a + b) / c) d;
{% validation %}
assert(x === (((a + b) / c)
d));
{% endexercise %}