JavaScript function HELP


#1

Hi all, a new user here and just learning JavaScript and would like some basic help please regarding this function task.

Any help would be greatly appreciated.

Thanks.

// Define quarter here.
var quarter = function(number){
return number /4;

if (quarter() % 3 === 0 ) {
console.log("The statement is true");
} else {
console.log("The statement is false");
}


#2

So far it looks good two little things

var quarter = function(number){
return number /4;
} // <<<< close the function
if (quarter() // <<<<  you call the function with no parameters try this quater(12) maybe

#3

ok cheers.

Last ? what is this code actually doing ?

return number /4;

if (quarter() % 3 === 0 )


#4

Okay i will try. First we look to the function quarter

var quarter = function(number){
    return number / 4;
}

If we call quarter(12); in the function number will be divide by 4
Number is 12 divide by 4 will return us the result 3

Now the if (){} statement

if (quarter(12) % 3 === 0 ){
DO this
}

is after passing through the function quarter

if (3 % 3 === 0 )

3 / 3 = 1 NO remainder. This statement is True. DO this will run
Other example

if (quarter(16) % 3 === 0 ){
  DO this
} else {
  DO that
}

16 / 4 is 4

   if (4 % 3 === 0 ){
      DO this
    } else {
      DO that
    }

4 / 3 = 3.33333333333 now we a have a remainder 0.333333333. This statement is False DO that will run.

hope i could give you a hint


#5

Pretty good just the modulo part went wrong. 4/3 is 1.3333... or 1+1/3. Meaning 3 fits 1 times inside of 4 and 1 is still remaining to be divided by 3. So 4/3 is 1 and a remainder of 1. So 4%3 will give you 1 (the remainder).
6%4 would probably be a better example because there you can distinguish the remainder from the integer result. 4 fits 1 times into 6 and 2 is the remainder so 6%4 is 2.


#6

Wahh thats totally right :smile: My fault


#7

Cheers its great to have help on here so if you do get stuck you don't need to spend hours wasting your time on it.