Functions and if/else lesson is bugged


#1



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


Currently stuck on this exercise. I have confirmed with a friend who knows Javascript that my code does exactly what it is supposed to. I've attempted to complete this lesson with this exact code in both Chrome and Firefox. In both browsers, it returns the error message, "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." I have come to the conclusion that this lesson is bugged. Could an admin please pass me through the lesson? 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));


#2

I think you not nessacary need to put the 'console.log' because your code at above already put 'return'

just put directly sleepCheck(5); or any number you wish in the bracket


#3

opps sorry..
I just checked and actually the console.log didn't affect anything..
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(5));

It still worked for me.. sorry


#4

yeah, the console.log is necessary because "return" just stores the value returned by the function in the "variable" that is the function. If I weren't to console.log it, it would only return the result of the last function due to a handy console function that echoes the last unaccounted variable.


#5

u can try copy paste my code to your page..
because my code worked for me..
or u try to refresh the page :slight_smile:


#6

I've tried refreshing the page already. Your code is literally identical to mine except for formatting. I appreciate your advice, but what I really need is to skip the lesson until it's fixed.


#7

I think I found your error already..
you should use "Get some more shut eye!"
instead of
"Get some more shut-eye!"

the "-" effect


#8

Thanks. That fixed it. It's kind of silly that I can't have dashes in my strings, but whatever.


#9

yea you need to follow the instruction completely.
sometimes it get me too..
haha