Microwave
_
+515|7109|Loughborough Uni / Leeds, UK
Alright everyone.


I've got a mini-test on the basics of javascript at my practical session tomorrow.


I have no previous knowledge of any programming so all this stuff is new to me.



I've managed to pick up most of it ok but I need help understanding this...




alert(Math.round(10/(11%4)));


The answer is 3.


I dont understand how the "%" symbol works. The rest is fine.



Cheers

Last edited by james@alienware (2008-10-05 10:04:37)

san4
The Mas
+311|7143|NYC, a place to live
Doesn't X % Y just mean the remainder when X is divided by Y?
liquidat0r
wtf.
+2,223|7081|UK
% = modulo operator

http://en.wikipedia.org/wiki/Modulo_operation

11 mod 4 = 3

10 / 3 = 3.33

round(3.33) = 3
Microwave
_
+515|7109|Loughborough Uni / Leeds, UK

liquidat0r wrote:

% = modulo operator

http://en.wikipedia.org/wiki/Modulo_operation

11 mod 4 = 3

10 / 3 = 3.33

round(3.33) = 3
So what in words does it do?


Nevermind got it.


Cheers

Last edited by james@alienware (2008-10-05 11:40:36)

Winston_Churchill
Bazinga!
+521|7193|Toronto | Canada

james@alienware wrote:

Alright everyone.


I've got a mini-test on the basics of javascript at my practical session tomorrow.


I have no previous knowledge of any programming so all this stuff is new to me.



I've managed to pick up most of it ok but I need help understanding this...




alert(Math.round(10/(11%4)));


The answer is 3.


I dont understand how the "%" symbol works. The rest is fine.



Cheers
11%4 - Divide 11 by 4 to the nearest whole number and give the remainder = 3
round(10/()) - Then 10 divided by 3 is 3.333333, which rounded = 3

Board footer

Privacy Policy - © 2025 Jeff Minard