The Modulus Operator

What exactly is the Modulus used for? Does it just store the remainder in a variable? Or is it used for more then that? I’m guessing i dived into code that isn’t my level yet…

The modulo operator gives you the remainder. The only works for integers.
You can store it as a variable if you wish.

remainder = 3 % 2

Thank you i understand that but i was looking at w3 school countdown timer where is was used but didnt understand its meaning…

Can you make a copy of the line?

Here it is…

var now = new Date().getTime();
var distance = countDownDate - now;

var seconds = Math.floor((distance % (1000 * 60)) / 1000);

Well, it is see how many seconds are left in the count down. I don’t know how they are doing there but I believe it goes something like:

total seconds % seconds in a minute = seconds left

Is the lesson specifically for the modulo operation?

No its not, do you recommend i watch videos about the modulo operation?

No, pull the code apart and look at the variables piece by piece. You know what modulo operators are. The problem is understanding everything else around it.

Thanks you for this, ill get to work

That applies only in the case of some languages. In Python, it also works for floats.

>>> 1.23 % 0.3
>>> 1.23/0.3

We can ignore the floating point error and just focus on 0.03 and 0.1 (the decimal fraction in the quotient).

0.1 * 0.3  =>  0.03