12. Functions & if/else // Unexpected token else syntaxError


SyntaxError: Unexpected token else, what am i missing?

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!";


else follows if, so whatever precedes your unexpected else is not an if


Found the error,

if (numHours >= 8); {
Should have been
if (numHours >= 8) {


When the condition in an if-statement is true, the following statement is executed.
If that statement is empty (semi-colon ends statements) then just that empty statement is executed.

{}'s are used to group multiple statements into one statement.


This assignment did not work out for me until I added an else if statement. The else alone, following the if would not work.


please share your code so we can see what you mean @kisabel86


i added "else if" but still the same unknown syntax error.


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!";

can someone helping with the above code: it is saying " unexpected token" in the console and "something wrong with syntax down the bottom. i have been looking at these for ages trying to work out what mistake I have made. still cannot think.


You don't have {} for the function. You should put { at the end of line 1 and }; before sleepCheck(10)


getting annoyed here with an error message, I am getting the correct output as I change the numbers but the lesson won't allow me to proceed. here is my code:

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

my code prompts this error even though the output is correct: Oops, try again. It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!" when numHours is 10. Check your if / else syntax and whether you're using the correct comparison operator.


I figured it out, it's because I didn't have an exclamation point after "much" in my if return string. jeez Louise! ...hopefully this is a lesson to someone else reading this. details are important