Functions, return and if / else 12


#1

from the Functions, return and if / else
there a something I don't understand guys why exactly the number 12 in the definition of the quarter in if statement
why not 6 or 9??
need someone to explain
thanks


#2

Can you supply with code?


#3

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


#4

So basically you are having troubles with:

ok so first lets take a look at the quarter function:

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

So we give it the number, and it returns the number/4... so basically we give it 12 and it returns 12/4, which is equal to 3... Right?

After that the other part of if statement

if (quarter(12) **% 3 === 0** ) {

I hope you know what modulus operator does.. basically it checks if it is divisble.. For example 4%2 will give you 0 since 4 is fully divisble by 2.. 4%3 will give you 1 since when you divide you go by 1 then halph.. Anyways that is math stuff.... So your essentially asking is 3%3 == 0.. Well obviously yes 3 does go into 3 fully so it does = 0 , resulting in executing the if statement.. Do you understand @ahmedtaha201177?


#5

yes i understand and thank you for interesting i think it's my fault i was understand that the return will be the last code to read from the computer but it seems that not right , thanks @amanuel2 <3