Oops, try again. It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!" when numHours is 10


#1

I'm a bit confused... could anyone help? I keep getting this error and I'm not sure what I'm supposed to change and I'm pretty sure it's correct... I might have missed a symbol or something? QAQ

(Oops, try again. It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!" when numHours is 10. Check your if / else syntax and whether you're using the correct comparison operator.)

This is my code:

var sleepCheck = function(numHours) {

if (numHours === 10) {
return "You're getting plenty of sleep! Maybe even too much";
}
else (numHours < 8); {
return "Get some more shut eye!";
}
};
sleepCheck(10);
sleepCheck(5);
sleepCheck(8);

12 Funtions if/else
#4

@nyuizumi,

You are using a semi-colon-; in the wrong place.

For Javascript a semi-colon-; is an End-of-Statement indicator,
causing the following code-block NOT being executed....!!!

Remove the semi-colon-;


#6

What @leonhard_wettengmx_n said plus else also doesn't need a condition as it is the default case if the if is not matched. And for the formatting just leave a blank line to the top and bottom of your code and add just three of these ` to this line this way you have a nicely formatted code with syntax highlighting. For indentations you can also use jsbeautifier.org


#7

I'm also having trouble. I've went throught this and switched stuff up. I can't seem to figure it out.
Here is my code:

// Write your function below. 
// Don't forget to call your function!
var sleepCheck = function(numHours) {
if (numHours >= 8) {
return ("Youre getting plenty of sleep! Maybe even too much!"); 
    }
}
else {
    return ("Get some more shut eye!");
}
sleepCheck(10);
sleepCheck(5);
sleepCheck(8);

#8

You close your function to early therefore the if is inside and the else is not which produces the error of an unexpected else. Also please post your questions in a separate thread if they are not concerning the OP question. Thank you.


#9

Hello. Looks like I'm getting the same error message. It actually returns the correct string, but the error message won't go away.

Here is my code:

var sleepCheck = function (numHours)

{
if (numHours >= 8) {
return "You're getting plenty of sleep!";
}
else {
return "Get some more shut eye!";

}
}
sleepCheck(5);
sleepCheck(10);


#10

Your messages seem to be shorter than those from the instructions. To pass they have to match exactly so maybe copy and paste those mentioned in the instruction or error message.


#11

Please help me in getting this error solved. I have double check but not able to get the error.

error:
Oops, try again. It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!" when numHours is 10. Check your if / else syntax and whether you're using the correct comparison operator.

Code:
/ Write your function below.
// Don't forget to call your function!

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

}

};
sleepCheck(10);
sleepCheck(5);
sleepCheck(8);


#12

Seems to be ok maybe an error in the output messages. Maybe copy and paste them from the instruction.


#13

Thanks for the help...code worked fine now.


#14

Not working here. This is beyond stupid.

Here is my code:

// 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
{
return "Get some more shut eye!";
}
};
sleepCheck(10);
sleepCheck(5);
sleepCheck(8);


#15

Ok, seems to be fine what is the error message? Did you try to refresh the page?
Also wrap your function calls in console.log if you want to see more than the echo of the last value.
Probably a typo in one of the messages, maybe copy and paste them. As said the code seems to be fine.


#16

Actually I printed out numHours before comparing it, and it makes no sense why the online editor would reject it. I'm not going to bother with codeacademy anymore.