Idk why the function doesn't return "Get some more shut eye!"


#1

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
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.

```

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!”;}};
console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));

and the result is:
You’re getting plenty of sleep! Maybe even too much!
You’re getting plenty of sleep! Maybe even too much!
You’re getting plenty of sleep! Maybe even too much!

<do not remove the three backticks above>

#2

Hi @systemsolver21952,

The if/else syntax can be seen like this:

if (condition) {
    // if condition is true
    // do this code
} else {
    // do this code instead
}

Now compare the above syntax to your code, see if you have added unnecessary symbols such as semicolon and quotation marks.

var sleepCheck=function(numHours){
if (numHours>=8); //<=== Check this
{return “You’re getting plenty of sleep! Maybe even too much!”;}
“else”;           //<=== Check this
{return “Get some more shut eye!”;}};
console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));

Compare those and remove the wrongful symbols, then your code should work.

An extra semicolon after your If statement will terminate the code before executing the code block after that.


:slight_smile:


#4

ohhhhhh it works now !!!


#5

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