Problem with function


#1

Hello,
I have the following issue. My code is running, however, I still get the error from the system. Please advice here.

My code is:

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

The result is:
“You’re getting plenty of sleep! Maybe even too much!”

Beside that, I still got the same 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.

I tried with different combination with return and console.log, doesn’t help.


#2

Are you asked to return this? Or to log it?

console.log(“You’re getting plenty of sleep! Maybe even too much!”);

#3

I"m ask to return it. I’ve tried all possible option with return and console.log. It still doesn’t run. I wonder what is the mistake or it’s a bug in the learning software.


#4

We will need a link to the exercise to investigate further. Please post one. Thanks.


#5

https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/4?curriculum_id=506324b3a7dffd00020bf661

Thank you Sir!


#7

The expectation of this exercise is return values for 10, 8 and 5 hours of sleep. Both branches of your conditional need to return a string, which above looks like you have copied them correctly from the instructions, also important. They must be identical.

The thing we do not need is parentheses around the return value. Drop parens on returns unless you are grouping in an expression. The value is already in quotes; that is explicit enough for the return to be a string object.


#8

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