Function if/else, very stuck. Please help!


#1



SyntaxError: Unexpected token


// Write your function below. 
// Don't forget to call your function!

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


#2

Do not include the semicolon after the closing brace.

Also,

Do not use a semi colon in this line because you are trying to start a function, and a semicolon says, "done with this section".


#3

same problem please reply me.I removed semicolons


#4

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

HELP!!


#5

It is not critical, but it helps with readability if you leave a space after a keyword.

return "something"

Be sure your strings are an exact match to the ones provided. Both of yours have a leading space inside the quotes that will not be accepted by the SCT.

else does not take a conditional expression. It's the default action.

else:
    # code

There are no semi-colons in an if statement structure.

if ( ) {

} else if ( ) {

} else {

}

Only the statements within their respective body receive a semi-colon at end of statement.


#8

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