Cannot get javascript code to compile

jcrew

Solid State Member
Messages
13
Location
US
Here are the instructions....

When we call a function, its return value is just the result from running the function. That value can then be used just like any other value in JavaScript!
Look at the if statement starting on line 7. The if statement is checking whether the result of calling the function named quarter is divisible by 3.

Instructions

  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.
Here is the code that is given:
// Define quarter here.

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

Here is the code I applied and it comes up error message when I compile it. What am I missing?
// Define quarter here.

function quarter(number)
if (quarter(12) % 3 === 0 ) {
return number/4
console.log("The statement is true");
} else {
console.log("The statement is false");
}
 
You have the function quarter mixed in with the code that calls it. You need to separate the function and put it where it says "// Define quarter here." If you switch the "if ..." line with the "return ..." line in your code you would be pretty close.
 
Also, you'll never actually hit the log function. Once you reach a "return" line, the function's done and you return to whatever called it.
 
I believe that the problem is, (from the code you pasted) that you don't really define a quarter function at all.

// Define quarter here.

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


funnily enough you need to do exactly as your comments suggest and define the function quarter.
Code:
//define quarter here
var quarter = function(passed_variable) {
var returned_variable =  passed_variable/4;
return returned_variable;
};

//now you can use the function

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