20. Math and the modulo


#1

I have a problem here:

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

And show this error:

Oops, try again. It looks like the second console.log() isn't quite right.

What i got to do??


#2

console.log(18 % 4); you dont have to make this one as a code this one is just for you. Do not put that one as a code leave it as it is : // console.log(18 % 4);


#3

@nicks_designs,

Javascript has the so-called modulo / remainder-operator if used it will return the rest-value.

9%3 You read it as nine modulo three is zero, as 9 divided by 3 has NO rest-value.
22%6 You read 22 modulo six is 4, as 22 divided by 6 will leave you with rest-value 4
16%8 You read it as sixteen modulo eight is zero, as sixteen divided by 8 has NO rest-value.
Now for the exercise 2/33:

var multiplesOfEight = [8,16,24,32,40,58];
                        |  |  |  |  |  |
      multiplesOfEight[0]  |  |  |  |  |
         multiplesOfEight[1]  |  |  |  |
            multiplesOfEight[2]  |  |  |
               multiplesOfEight[3]  |  |
                  multiplesOfEight[4]  |
                     multiplesOfEight[5]

multiplesOfEight[0] --> 8
multiplesOfEight[2] --> 24
multiplesOfEight[5] --> 58

multiplesOfEight[0]%8 --> 8%8 --> 0
multiplesOfEight[2]%8 --> 24%8 --> 0
multiplesOfEight[5]%8 --> 58%8 --> 2

google search
== the Book ==
javascript remainder operator site:developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

== discussions / opinions ==
javascript remainder operator site:stackoverflow.com
http://stackoverflow.com/questions/4467539/javascript-modulo-not-behaving
javascript array site:developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators

== guidance ==
www.crockford.com
http://javascript.crockford.com/survey.html
http://javascript.crockford.com/code.html


#4

Thanks @terarunner40174