Modulo logic?


#1

I've been going over the math a million times, but I just don't get the logic behind the modulo symbol. It says 17 % 5 means its dividing 17 by 5, but that does in no way result in 2. Can anyone please explain this apparently easy math to me?


#2

A million times? In less than the time needed to read this phrase I already had it searched. Did this generation never do any whole number division? Are remainders that foreign?


#3

17 % 5 is not typically 17 divided by 5, but it actually means of what the remainder is when you divide the number. For example, 19 % 2 would equal 1. Why? It's because 19 divided by 2 gives a remainder of 1. Same with 17 % 5. If you divide 17 with 5, you get 3 remainder 2! That's why the answer is 2. % gives the remainder, not the actual answer.

Hope it helped! :smile:


#5

Please help me... 14%3


#6

14%3

4 remainder is 2


#7
     4
  -----
3 ) 14
   -12
  -----
     2  => remainder

So, 14 % 3 === 2.


#8

I don't get this;

// console.log (14%3)

is reading; did you console log() the result of 14%


#9

if you hav 17 % 5 you need to ask how many times can you put 5 into 17
the answer is 3 times but you still have 2 left that 2 is the answer

another example is
22 % 10
how many times can you put 10 into 22
answer 2 times than you got 20 but your left with 2
so 2 is the answer

if it isn't clear plz tell me


#10

We have to remove the single line comment token, //.

console.log(14 % 3);