Skip to content

Commit 3f7a120

Browse files
Merge pull request #423 from TomHodson91/patch-1
Added extra basic maths operators
2 parents e4a3b8b + 609ab84 commit 3f7a120

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

js/lesson2/tutorial.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,36 @@ console.log('Division: x / y = ' + division); // Division: x / y = 2
8181

8282
> Why not try some other maths problem using the `x` and `y` variables?
8383
84+
#### More maths
85+
86+
Other basic but useful math operators are `%`, `**`, `++` and `--`:
87+
88+
> The modulus `%` operator returns the remainder when dividing one operand by another.
89+
90+
> The exponentiation `**` operator returns the result of raising the first operand to the power of the second.
91+
92+
> The increment `++` and decrement `--` operators return the result of adding one and subtracting one from an operand respectively.
93+
94+
```js
95+
var x = 5;
96+
var y = 3;
97+
var modulus = x % y;
98+
99+
console.log('Remainder: x % y = ' + modulus);
100+
101+
var exponentiation = x ** y;
102+
103+
console.log('Exponentiation: x ** y = ' + exponentiation);
104+
105+
var increment = x++;
106+
107+
console.log('Increment: x++ = ' + increment);
108+
109+
var decrement = y--;
110+
111+
console.log('Decrement: y-- = ' + decrement);
112+
```
113+
84114
#### Comparisons
85115

86116
The `===` operator compares two values, it returns the boolean `true` if they are equal and `false` if they are not.

0 commit comments

Comments
 (0)