Functions and returns syntax error lesson 8


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-6LzGd/1/3?curriculum_id=506324b3a7dffd00020bf661#


SyntaxError: Unexpected token %
Oops, try again. There was a problem with your syntax.


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


#2

Show me your all code.


#3

this is it.

// Define quarter here.

is what i need to do


#4

You need to define function first and after that use it.
You're putting incomplete function expression inside if statement.


#5

I understand that, just don't know how.


#6

This code should work:

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

You can always ask what specifically you don't understand. First 3 lines define a function expression with a body and it returns a value. Everything that is below function expression is just if/else construct to check if given number is divisible by 3.


#7

thank you for this. this help a lot.


#8

Thank you so much! My error is forgetting a ( ) or {}.


#9

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