Functions & if / else - SleepCheck help!


#1

Hi, I don't know what's wrong with my code. It says "Oops, try again. There was a problem with your syntax."

Line 7 shows an error message saying: "Expected and identifier and instead saw 'else'. Missing ";" before statement" but I don't know how to fix this issue.


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


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


#2

Just looking at the code, the semicolon after your if statement conditional should be a curly brace, though otherwise your code is identical to my own and it doesn't seem to be working. Anyway, hope this brings you a step closer to the solution.

quick edit, you also need to close the curly brace for the block of function code.


#3

Exactly right.
The semi-colon after the 'if' statement is stopping everything
Curly brace there and one at the end of the function and the code looks good!


#4

I see! Thanks very much. It's working now :slight_smile:


#5

Glad you got it working, discovered my own wasn't passing as has a spelling error in the string!


#6

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