8. Functions, return and if / else please help my code runs but I don't understand part of it


#1

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

//if i run this it works but it is not equal to 0 so why does it work? Im not sure i understand how the "===" works
if (quarter(24) % 3 === 0 ) {
console.log("The statement is true");
} else {
console.log("The statement is false");
}


#2

Hey,

There's a nice explanation here https://www.codecademy.com/articles/glossary-javascript

the "===" is basically equals "=" in regular math
% (modulus) returns the remainder after dividing left/right numbers, example:

10%3 === 1, because 3*3=9 and the remainder is 1
24%3 ===0, because 24/3=8 and there isn't any remainder after diving those two numbers, hence 0...

This is how I understood it, hope I got it right and hope it helps...


#3

am stacked, please I need help.

var quarter=function(number)
{return number/4;};
if (quarter(24)%3===0)
{console.log("The statement is true")}
else {console.log("The statement is false")};


#4

danquah1

you shouldn't print semi-colon before the bracket in the same line
like this {return number/4;}; =====> {return number/4};

you may do it like this...

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


#5

It is still not working..

var quarter=function(number){
return number/4;
};
if (quarter(24)%3===0){
console.log ("The statement is true");
}else{
console.log ("The statement is false");
}


#6

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

It's work


#7

Make sure you spell everything right. It should be quarter and not guarter, (q as the first letter and not g). I did the same mistake.