Functions & if / else


#1

// 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(numHours < 8
return "Get some more shut eye!";
}
{
var sleepResult = function(10);
console.log(sleepResult);
var sleepResult = function(5);
console.log(sleepResult);
var sleepResult = function(8);
console.log(sleepResult);
}

please help me understand what I'm forgetting, thanks


#2

When making comparisons in a condition, those should be together (>=), since Javascript is space sensitive.

Also, if numHours is not higher or equal to 8, it's an understatement that, otherwise, it'll go trough the else part, so it isn't really necessary to ask that again (you'll see more complex if statements later). It should look like this:

if(condition) {
    return #something
} else {
    return #another thing
}

#3

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