JS 8/13 Syntax Error: Unexpected token else


#1

I'm having trouble with the Return IF/Else exercise.

This is my code:

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

however i'm getting a syntax error of Unexpected token else.

Can anyone help?


#2
if (quarter)(12)( 3 === 0 )

this line has some problems with its (). currently the conditions would be quarter and the stuff to do in case of true whould be 12 then the statement would end because of the normal code following and then out of no where an else would appear. So you get the error. So better include the quarter(12) like this:

if (quarter(12) % 3 === 0 )

#3

Thanks @haxor789 when i do this i get unexpected ) token


#4

Could you post the updated code? For me this change would work.


#5

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


#6

Ok yes you still have the closing ) here:

if (quarter   **)**   (12) % 3 === 0)

What you do here is just to call the quarter function with an argument of 12 so just quarter(12) what you get returned is 12/4 aka 3 which is obviously without rest divisible by 3.


#7

@haxor789 many thanks, that fixed it.