8. Functions, return and if/else


#1


// Define quarter here.

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

My code seems to be alright. I am just wondering, if we're trying to find out if the number is exactly divisible by 3, shouldn't you define in the quarter function as "return number / 3" ? I may have the maths confused here, could someone explain this to me ? Thanks in advance.


#2

Hi it works like that ..

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

the you call it

quarter(12)

12/4

#Output

3

so inside the if statement it's like that

if (3 % 3 === 0 )

which is true

so

the number is first divide by 4 then the result of that division is is check inisde the if statement if is divisible by 3.
Hope that could help you understand it


#3

after the return number/4 there is a } put a (:wink: so it goes like this
};
it is very important to follow to read the code carefully.

if (code != read carefully);
console(" many days loss!!");

only plaing!!! :wink:


#4

and after the 4 ; to you have to do it so it work!!!!


#5

see!!
// Define quarter here.
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");
}


#6

That makes so much sense, thank you so much guys, you really have been helpful!! :smiley: