Lesson 8 Return and if/else


#1


I'm just having a really hard time trying to figure out why I cant make the code do what I want. maybe its my formatting? or maybe its my crappy math skills....can anyone give me a hint?


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

quarter(30)


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


#2

so your not actually going to call the quarter function with a number in it outside of your if statement but inside! I can give more of an example if you need it but that should be enough of a hint to push you in the right direction.


#3

Okay thank you very much bibleman13.
I fixed the code like this:

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

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


The statement returned true. On the other hand. I'm still not sure why this worked..can you point me in the direction of where I can find some clues as to why coding the call function inside of the if statement made such a difference?


#4

This line is not needed as you have already made the call earlier in the if statement.


#6

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