Skip to content

Added extra basic maths operators #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions js/lesson2/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,36 @@ console.log('Division: x / y = ' + division);

> Why not try some other maths problem using the `x` and `y` variables?

#### More maths

Other basic but useful math operators are `%`, `**`, `++` and `--`:

> The modulus `%` operator returns the remainder when dividing one operand by another.

> The exponentiation `**` operator returns the result of raising the first operand to the power of the second.

> The increment `++` and decrement `--` operators return the result of adding one and subtracting one from an operand respectively.

```js
var x = 5;
var y = 3;
var modulus = x % y;

console.log('Remainder: x % y = ' + modulus);

var exponentiation = x ** y;

console.log('Exponentiation: x ** y = ' + exponentiation);

var increment = x++;

console.log('Increment: x++ = ' + increment);

var decrement = y--;

console.log('Decrement: y-- = ' + decrement);
```

#### Comparisons

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