How to call a function inside a loop


#1



my code doesn't work as it seems that i should call the function inside the IF loop.

// 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");
}

#3

Which you are doing, so that much is correct. However, the function takes one argument, number which you need to pass in the function call.

Consider that the instructions ask for a return of true so that means the return value from your quarter() function will need to be divisible by 3. That suggests an LCM type of problem. What number could you pass the function that is both divisible by 4 and by 3? Answer: Any that are multiples of the LCM of 3 and 4.

[0, 12, 24, 36, ...]

I added in 0 because it is a valid answer, in a sense. Any in this list will work.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.