Modulo


#1

could somebody help tell me what I am doing wrong here:

14 % 3 console.log ( 2 );
99 % 8 console.log ( 3 );
11 % 3 console.log ( 2 );


#2

There is a comment over your code!

// Below is an example of printing the remainder of 18/4 using modulo
//console.log(18 % 4);

There you can read what you did wrong.


#3

Do you have a problem understanding modulo or is it just the printing of it?


#4

I understand the concept of modulo, just the printing is the problem. There seems to be a problem with my syntax and I don't understand where it lies. For example do you put "console.log" first before modulo, like -
console.log ( 14 % 3 console.log ) 2 ; or
14 % 3 console.log ( 2 ); like I have above?


#5

Excuse me, type. Here it is:

console.log ( 14 % 3 ) 2 ; or
14 % 3 console.log ( 2 );


#6

I got it!! Here is how it should be:

if (14 % 3) { console.log (2); }
if (99 % 8) { console.log (3); }
if (11 % 3) { console.log (2); }

Thank everybody for trying to help. I am sure I will have to pick your brain later. You are doing a noble job helping out people that are stacked. Keep it up and I will do likewise if I can, although just started coding.


#7

You didnt got it!

Try this

if (16 % 3) { console.log (2); }
if (109 % 8) { console.log (3); }
if (4 % 3) { console.log (2); }

This are other values but same wrong results or :wink:

So here is the right code for this lesson

console.log(14%3);
console.log(99%8);
console.log(11%3);

If you now change maybe 14 into 16 you get the result 1 and not 2!