Functions & if/else


#1

Can someone help me please? I'm trying to figure out what's wrong with my code and it's frustrating me. Also, why does it say, "Illegal return statement"?



Replace this line with your code.


#2

Your if/else should be inside sleepCheck function.

hint--

var anyName  = function (parameter) {
    if (condition)
    {
        //yourcode
    }
    
    else 
    {
        //yourcode
    }
};

#3

It didn't work.


#4

You missed the last closing curly bracket. (of function)


#5

var sleepCheck = function(numHours) {
}

This closing bracket? If so, I did that in the first pic and it still won't run. Sorry about this, just to figure it out.


#6

Put there a } (closing curly bracket) after already existing }


#7

Thank you so much for your help! I had to put a semicolon after the closing curly bracket also.

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


#8

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