12. function and if else


#1

I NEED HELP WHAT DID I DO WRONG
// 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!";
}
console.log(sleepCheck(10);
console.log(sleepCheck(5);
console.log(sleepCheck(8);


#2

Hi your if condition should be inside () like that

if (numHours >= 8) {  <== you should add one

An your console.log should be like that

console.log(sleepCheck(10)) <== add one

#3

HI,

Sorry i ride on this thread but since it is the same topic, will be grateful if somebody can point out to me what is wrong here? THANK YOU!

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


#4

@10317366 and @nonconformity You also both lack a } to close your function.


#5

OHHHHH!

Thank you so much!


#6

Hi, thank you for the replies above, I'm still having issues.

var sleepCheck = function(numHours)
{
if (numHours >= 8) {
return "You're getting enough sleep! Maybe even too much!";

}
else { 
    return "Get some more shut eye!";

}

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

I get the error message: 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.

Even though the code seems to be working just fine, it IS returning the correct string!
I've also tried logging just one answer at a time, with the same results.

Please help. I seem to have similar problems all through this section.


#7

Compare

And the string in the error

This exercise is very specific about the right string being used.


#8

-.-
I've checked this so many time, can't believe I've missed it every time!

Thank you!


#9

A post was split to a new topic: This code is not returning "Get some more shut eye!"