* feat(curriculum): Add Basic JS Scrimba links * Fix: Add missing video url. * fix: update videoUrl
2.0 KiB
2.0 KiB
id, title, challengeType, videoUrl
id | title | challengeType | videoUrl |
---|---|---|---|
56533eb9ac21ba0edf2244ae | Finding a Remainder in JavaScript | 1 | https://scrimba.com/c/cWP24Ub |
Description
%
gives the remainder of the division of two numbers.
Example
5 % 2 = 1 becauseUsage
Math.floor(5 / 2) = 2 (Quotient)
2 * 2 = 4
5 - 4 = 1 (Remainder)
In mathematics, a number can be checked to be even or odd by checking the remainder of the division of the number by
2
.
17 % 2 = 1 (17 is Odd)Note
48 % 2 = 0 (48 is Even)
The remainder operator is sometimes incorrectly referred to as the "modulus" operator. It is very similar to modulus, but does not work properly with negative numbers.
Instructions
remainder
equal to the remainder of 11
divided by 3
using the remainder (%
) operator.
Tests
tests:
- text: The variable <code>remainder</code> should be initialized
testString: assert(/var\s+?remainder/.test(code), 'The variable <code>remainder</code> should be initialized');
- text: The value of <code>remainder</code> should be <code>2</code>
testString: assert(remainder === 2, 'The value of <code>remainder</code> should be <code>2</code>');
- text: You should use the <code>%</code> operator
testString: assert(/\s+?remainder\s*?=\s*?.*%.*;/.test(code), 'You should use the <code>%</code> operator');
Challenge Seed
// Only change code below this line
var remainder;
After Test
(function(y){return 'remainder = '+y;})(remainder);
Solution
var remainder = 11 % 3;