8. Functions, return if/else: Calling the Function


#1

The question I am on is .03 Call the function inside the if statement's condition (and put in a parameter value!) such that "The statement is true" is printed to the console. My problem is Oops, try again. You did not call the quarter function! You made it, now use it! How do I do this with the code below?

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

8. Functions, return and if/ else
#2

Hello @bibleman13,

You have to pass a number as an argument to the function quarter you have just defined, like this

quarter(rand_number) //where rand_num is a random number

Hope this answers your question...


#3

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

When I do this with any number I get the quarter is not defined and I am still not calling the quarter apparently. So am I just missing the point of your comment or do I need a certain number....


#4

No, change the call to quarter in your original if statement by adding a number in parentheses after it...


#5

Ahhhh Thank you very much! I was thinking you had to individually call it outside of the if else statement...Slow yes but I gotcha now.


#6

No worries, @bibleman13. If you feel satisfied with my solution, please mark it down as the solution so that others know that the topic is closed...


#7

Yes I was just finding the button so yes it is marked as solved now


#8

I'm trying to follow along here and I think I'm running into the same problem but i'm just not following.

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

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

#9

Actually I figured it out! just had to read a few more times.


#10

I am so lost.... what is the point of [return number/4]? Like I dont know why this is relevant to trying to determine (quarter() % 3 === 0).


#11

Hello @victorberrios,

This exercise teaches you how to make and call a function. So while the function quarter() had nothing to do with determining whether a number is divisible by three, the point of this exercise is fulfilled since you have both defined and called the function... Hope this clears things out for you...


#12

I seriously just changed the console.log("The statement is false"); to console.log("The statement is true");, i couldnt figuire it out either but i just made a pointless if else statement. WORKED THOUGH


#13

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

Since the function will divide the number by 4, you have to put in a number that when divided by 3 will give you a remainder of 0. That is why I put 12 inside the parenthesis, because when divided by 3, you get a remainder ( % ) of 0.


#14

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