Syntax error on JS functions lesson 12


#1

On lesson 12, it says, "Unexpected token if". My code is:

var sleepCheck = function(numHours)
if (numHours >= 8) {
return "You're getting plentry of sleep! Maybe even too much!";
}
else {
return "Get some more shut eye!";
}
sleepCheck(10);
sleepCheck(5);
sleepCheck(8);
};

@stetim94 I know you've done this before. Please help!


#2

YYou wrap the action of a function inside brackets, which you forgot to do.
You also have an extra closing bracket after you called the function.


#3

Ah ok. Thanks for the help!


#4

Hi, can you help me too?

I can't find my error...
This is what it says: SyntaxError: Unexpected token else

var sleepCheck = function(numHours) {
    
    if(numHours => 8) 
    {
        return "You're getting plenty of sleep! Maybe even too much!";
    }
    else
    {
        return "Get some more shut eye!";
    }
};

sleepCheck(10)
sleepCheck(5)
sleepCheck(8)

#5

For the correct operand, then equal sign goes after the greater than sign.


#6

Thanks rhyscrypto!

Little (Big) detail :wink:


#7

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