8. Functions, return and if / else


#1

I need help with 8. Functions, return and if / else, this is the code I have so far and it is saying its wrong. Can someone please correct it.

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

console.log(number/4)

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


#2

Hi shazapatel.
first of this code should not be a "console.log(number/4)" you should change it to a return statement.


#3

Because you want too return a value not log it onto the console.
hope this helped.


#4

I am stuck with calling the function inside the if statement condition in the below code.
Can you help me to know how to call the function?
var quarter= function(number)
return number/4;

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


#5

Hi gayu.suj,

I'm also new at coding, here is my correct code:

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

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

you must add a parameter value to quarter() in if statement's condition line.
Also, you forgot curly brackets in the function code.


#6

Hi barone,

I am interested why only 12 is ok? I think because we can devide it whit 4 and 3? Or if you can, please, explain this to me.


#7

12, 24, 36, 48, 60....

"We want quarter(some number) that when divided by 3 has remainder 0" like explained in Hint section.


#8

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