0

JavaScript modulus question

Can someone please explain how modulus works %

24th Dec 2018, 3:38 PM
Andrew
8 Réponses
24th Dec 2018, 3:47 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
Let's talk in integers, if you divide 12 by 24 then smallest number you can multiply 24 with to get a number smaller than 12 is only 0 (not talking about decimals here) so, 12-24*0=12
24th Dec 2018, 4:04 PM
Mayank Dhillon
Mayank Dhillon - avatar
+ 1
thank you when i was figuring it out i was adding a decimal so my remainder didnt match the correct answer i got it now
24th Dec 2018, 4:14 PM
Andrew
0
it is an operator which gives you remainder 10%2 gives 0 as 2*5 = 10 and 10 - 10 =0 10%3 gives 1 as 3*3 = 9 and 10 -9 = 1 Why are you even asking this?
24th Dec 2018, 3:45 PM
Mayank Dhillon
Mayank Dhillon - avatar
0
thats what i thought it was but i came across this question what is the output of this code? x= 12; y= 24; z= x % 24; alert(z)
24th Dec 2018, 3:58 PM
Andrew
0
the answer is 12 but im not understanding why
24th Dec 2018, 3:59 PM
Andrew
0
The output is 12 because 24 is greater than 12
24th Dec 2018, 4:01 PM
Mayank Dhillon
Mayank Dhillon - avatar