Functions and if/else


#1



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

It says "Syntax Error!". I can't find out the error. please help!


#2

Your function is missing { }

After (numHours) you need to have your opening curly bracket and you need to close it after your else statement
When closing your if statement remove the semi colon from after the curly bracket.


#3

Oh it works!!! Thank you very much. But, I don't understand why we need to put curly bracket before if statement. Can you please explain to me?


#4

You mean the function? Why you need to add curly brackets to the function?

As whatever is in the curly brackets is what in the function, the first line declares the function..


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

pls someone should help me figure out the syntax error. i cant see it myself.


#6

This semi colon needs to go