# Functions, return and if/else

#1

Hello everyone!

i am stuck on what i am actually meant to do at this stage...

here is the instructions on what I am meant to do:
1) Define a function called quarter which has a parameter called number.
2) This function returns a value equal to one quarter of the parameter. (i.e. number / 4;)
3)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.

This is the default code given:

// Define quarter here.

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

This is what I have done so far and i think i am going the wrong direction but can't get my head around it:
var quarter = function (number)

if (quarter() number / 4 ) {
console.log("The statement is true");
} else {
console.log("The statement is false");
}

Help explaining what i am meant to do step by step would be great!
Many Thanks

#2

Hi,

1) Define a function called quarter which has a parameter called number.

``````def quarter = function(number){

}``````

2) This function returns a value equal to one quarter of the parameter. (i.e. number / 4;)

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

3)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.

``````if ( quarter("here type a number") % 3 === 0) {
console.log( "The statement is true")
}
else {
console.log(" The statement is false")
}``````

Inside quarter() you should put a number that the remain of the division by 3 is equale to 0 like that

``12 % 3 === 0``

#3

@theocanes
Hi,
First of all you must create a function called `quarter` that will return the quarter of the parameter. Remember a function syntax looks like this:

``````var functionName = function(optional parameter) {
//the codes runs inside of here
};``````

Then like the instruction says, you will use the return function to return the value of a quarter of the parameter. I guess you have a hint right here:

So next finally you have the `if-else` statement which you need to print the statement is true by using the quarter function. Remember, you can call a function like this:

``functionName(optional parameters to input);``

Codeacademy has already put the code to call the function, you just need to define the** parameter** inside of the pair of the pair of parentheses next to your `quarter function`. Make sure your if statement should return the statement is true. Your code should look like this:

``````if (quarter(/* Here, you put the number you want */) % 3 === 0) {
console.log("The statement is true");
} else {
console.log("The statement is false");
}``````

Hope this helped you.

#4

Hello, thanks for the reply, on the line of the if statement is the "here put the number you want" a string or a number?
Thanks

#5

This is my code so far:
var quarter = function (number)
{
return number / 4;
}

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

And the error says:
Did you remember to call quarter() inside the if statement with a value that would cause it to print 'The statement is true'?
The console also outputs to "the statement is false"

#6

@theocanes
When I say a number, you should refer it as an integer or float value, not strings (in which I would have precised anyway).

# Look here

In the if statement, it will first find the quarter of 16 (which is four) and test whether quarter of 16 % 3 === 0. \$ isn't evenly divisible by 3 (16 % 3 === 1) so that's why it prints false. You must find a number (you know what I'm talking about) which quarter is evenly divisible by 3. Understood?

#7

finally got it done!
thank you so much for the help