Bug in course 11: "Functions and if else"


#1

I've come across this problem before, where the course engine appears to be "very clearly incorrect". Let me know if this error is out of place or my (very simple) code is no good:

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

I love the UI of Codecademy but this is the second time I've had the engine not let me pass what seems to be a correct piece of code.

Thanks!


#2

Hello @nick.walt.

Call the function with 10 hours of sleep, like this: sleepCheck(10);
Call the function with 5 hours of sleep.
Call the function with 8 hours of sleep.

It seems that you need to call them all at onece in youre code. Like this:

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

#3

The text string for your else statement returns:

 "Get some more shut-eye"!

The text string you need to use is:

"Get some more shut eye!"


#4

Haha, yeah I should learn to question my own code (ugh, and to check for typos) before I question Codecademy :slight_smile: Thanks for responding, biff.

Although, just reading the error message again, it mentions checking syntax and whether I'm using the correct operator, which isn't at all good feedback. I don't know why Codecademy doesn't also check the string and either:

  1. just ignore the string in the code; or
  2. warn that the string doesn't match the required input.

#5

The tweaked code to provide more granularity. Is there a better way to write this?

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

#6

Better in what sense?


#7

Maybe a way that doesn't use if else. Not sure if this can be done using a hash. I guess it is too simple to distill down to anything else. Cheers


#8

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