Functions, Return and If / Else


#1

Code is True when "return (number)/4;" and False when "return number/4;".
Why? It is should be True when "return number/4;" .

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


#2

No, that makes no difference. Something is wrong about that observation, perhaps you changed something else as well.


#3

No changes except this
var quarter = function(number) {
return (number)/4;
};

And this is meaning of syntax.
Exercise is ok when number between parenthesis.


#4

Post both versions?


#5

Sure

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

// 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

Did you also run them and test whether they produce different output?
They do not


#7

They produce "The statement is true", both.


#8

Wasn't the problem that they didn't?


#9

Sorry, i mean this "return quater(number)/4".


#10

If you divide a quarter by four then you have one sixteenth. Why would 1/16 % 3 be true?

It's an infinite loop too - quarter calling itself each time it is called


#11

Counterquestion.
So why


#12

Why what? No mind reading here


#13

Interpreter telling me "quater is not defined" and let me through to next exercise.
So quater can be not defined?


#14

Why wouldn't it be possible to define quater?

var quater = 5;

It probably passes because the exercise's author didn't anticipate the situation you created. That's somewhat common actually (but you should be verifying your own code either way, it's important to see the effects of what you write)


#15

Agree, i'm testing my code several times with possible options. But time to time found something unusual here.
Anyway thx for spent time.


#16

If you defined a function, and quater isn't defined, then the function must surely have a different name?