2018-10-10 18:03:03 -04:00
---
id: 56533eb9ac21ba0edf2244ae
2021-02-06 04:42:36 +00:00
title: Finding a Remainder in JavaScript
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-04-29 18:29:13 +08:00
videoUrl: 'https://scrimba.com/c/cWP24Ub'
forumTopicId: 18184
2021-01-13 03:31:00 +01:00
dashedName: finding-a-remainder-in-javascript
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
The < dfn > remainder</ dfn > operator `%` gives the remainder of the division of two numbers.
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
**Example**
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
< blockquote > 5 % 2 = 1 because< br > Math.floor(5 / 2) = 2 (Quotient)< br > 2 * 2 = 4< br > 5 - 4 = 1 (Remainder)< / blockquote >
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
**Usage**
In mathematics, a number can be checked to be even or odd by checking the remainder of the division of the number by `2` .
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
< blockquote > 17 % 2 = 1 (17 is Odd)< br > 48 % 2 = 0 (48 is Even)< / blockquote >
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
**Note**
The < dfn > remainder< / dfn > operator is sometimes incorrectly referred to as the "modulus" operator. It is very similar to modulus, but does not work properly with negative numbers.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Set `remainder` equal to the remainder of `11` divided by `3` using the < dfn > remainder</ dfn > (`%` ) operator.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
The variable `remainder` should be initialized
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(/var\s+?remainder/.test(code));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
The value of `remainder` should be `2`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(remainder === 2);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
You should use the `%` operator
2020-04-29 18:29:13 +08:00
2018-10-10 18:03:03 -04:00
```js
2021-02-06 04:42:36 +00:00
assert(/\s+?remainder\s*?=\s*?.*%.*;?/.test(code));
2018-10-10 18:03:03 -04:00
```
2020-04-29 18:29:13 +08:00
2021-01-13 03:31:00 +01:00
# --seed--
## --after-user-code--
```js
(function(y){return 'remainder = '+y;})(remainder);
```
## --seed-contents--
```js
// Only change code below this line
var remainder;
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
var remainder = 11 % 3;
```