Skip to content

Commit 609ab84

Browse files
authored
Added extra basic maths operators
Added the modulus, exponentiation, increment and decrement operators after the 'Maths' section. These are basic and commonly used maths operators in JavaScript. To avoid having too many examples in one example snippet and allow for easily digestible information, I've added a new sub-heading called 'More Maths' to contain these new examples.
1 parent b525f36 commit 609ab84

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);
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)