Please help in lesson 8. It keeps on saying the syntax is wrong


#1

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

Thanks.


#2

Hi
there are indeed several syntax errors. Please read the introduction
https://www.codecademy.com/en/courses/javascript-beginner-en-6LzGd/0/3?curriculum_id=506324b3a7dffd00020bf661

The general syntax for a function is

var greeting = function (name) {
    console.log("Great to see you," + " " + name);
};

Here the function is named "greeting" and receives "name" as a parameter. The "var" and "function" are common to all the functions. The two things that will differentiate them are the name of the function and the parameters that are given in brackets.
Then the function can be called by

greeting("Annabelle")

In your case, it is a bad idea to give the value 12 in the parameters of your function. The value of the parameter should be given when you are calling your function. Moreover, the name of the function is missing.


#3

Thank you very much thebelgian1! It really helped!


#4

Hi!

Could someone explaine why the function below is correct:
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");
}

And this one is not:

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

What I mean is if we can call a function without returning a value?


#5

In a general case, yes, it is not mandatory for a function to return something. For example, it can just print something on the screen. But as printing on the screen is a pretty limited operation, it is not so interesting to do such things. Function are very often used in order to perform a specific task and to return the result of the operation. In the example that you gave, the first function returns the result, which can then be printed by the console as done in the last lines of your code. However, the second function does not return the result and it does not print it either. So the second function is not very useful.