Functions & if / else not passing


#1

Hi. I seem to be coding the function correctly. It works for the first callout but not the second, which should invoke the "else" of the function.

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 shuteye!";
    }
};
sleepCheck(8);
sleepCheck(5);
sleepCheck(10);

Can anyone see what I am missing? Thanks in advance!


#2

You aren't asking it to print the results. You can do that by adding console.logs to each of your function calls, like this:

console.log(sleepCheck(8));

Do you see how that works?


#3

Mmm, this is weird,

For instance I seem to have the correct code in place, as I get the statements printed out, however the task will not pass, I get the below error:

Oops, try again. It looks like your function doesn't return "Get some more shut eye!" when numHours is 5. Check your if / else syntax and whether you're using the correct comparison operator.

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

};
console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));


#4

"Get some more shut eye!"
"Get some more shuteye!"


#5

But then why am I getting the right statements printed out to the console?


#6

I don't understand, are you saying, that even though your code has the incorrect "Get some more shuteye!", that the correct "Get some more shut eye!" is being printed?


#7

my bad there was a spelling mistake, doh!


#8

Yes, thanks very much!