freeCodeCamp Challenge Guide: Finding a Remainder in JavaScript

Finding a Remainder in JavaScript


Hints

Hint 1

The remainder operator % gives the remainder of the division of two numbers.

var remainder = 11 % 3; //remainder gets the value 2
3 Likes

I have been struggling to get this formatted correctly. Any help would be appreciated. I put:

(11 % 3 = 2);

for my answer and it has a yellow caution triangle and says “Bad Assignment” pointing to the equals sign.

3 Likes

var remainder = 2 % 11;

7 Likes

The remainder operator % gives the remainder of the division of two numbers.
Example
Usage
Note

Instructions
Set remainder equal to the remainder of 11 divided by 3 using the remainder (%) operator.

  1. The variable remainder should be initialized
    var remainder

2)The value of remainder should be 2
var remainder = 2;

  1. You should use the % operator
    var remainder = 2%11;

`

7 Likes

Can anyone clarify what they’re saying here?

17 % 2 = 1 (17 is Odd)
48 % 2 = 0 (48 is Even)

“Set remainder equal to the remainder of 11 divided by 3 using the remainder (%) operator.”

var remainder = 2%11;

Where did 11 / 3 go?

The above was an example. It is pretty easy but everyone has to be verbose when explaining shit here.

For 11 % 3 all you do is divide 11/3, which =3 with a remainder of 2.

can double check by 3x3=9
11-9=2(same as the remainder)

10 Likes

I have no idea what the final part of this task was on about.

I understand the following
17 % 2 = 1 (17 is Odd)
48 % 2 = 0 (48 is Even)

In the final part, the correct answer is var remainder = 2 % 11;, but I have no idea what this has to do with 11 / 3.

5 Likes

I entered “var remainder = 11 % 3;”, which the system accepted as correct. However, looking here I see var remainder = 2 % 11; is supposed to be the correct answer. Can anyone please clarify whether 11 % 3 really is the correct syntax, and if not, why not? TIA.

7 Likes

I think it’s this

var remainder = 11 % 3;
9 Likes

Some info about the operator https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Remainder_()

I think free code camp accepts the answer because the result of 2 % 11 is coincidentally the same 11 % 3.

I got a bit confused about what they wanted, because they were talking about finding whether a number was odd or even earlier on in the tutorial.

5 Likes

There are several answeres possible you can also sollute the lesson by

var remainder = 11 % 3;