Syntax error on Functions & if/else


#1


Hi All,

I keep getting the error SyntaxError: Unexpected token { and can't for the life of me figure it out. Any help is greatly appreciated. Code included below.

Thanks!!!


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

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


#3

else statements do not take parameters, only else if().

Your code should look like this:

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

#4

Ah that's it. Great! Thanks @itschrisburton


#5

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

this is what I have and I had what @itschrisburton shared, but it keeps telling me that my if/else statement does not return the second part of the if/else statement ("Get some more shut eye!").


#6

Try refreshing the page


#7

I did, it still gave me the same error. Ended up using your code, but I don't understand why I was getting an error :confused:


#8

Could it be the uppercase "S" in "Shut"?


#9

Honestly, it probably was.


#10

yup. That's what it was...


#11

It's always the little things.


#12

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