I don't know what I did wrong - Functions and if/else, 12


#1


Hi.
I have gone through my code and can't find the mistake. I would really appreciate any help.
Here is the link:

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

This is the error message I keep receiving:

SyntaxError: Unexpected token {

This is my code:

// 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(numHours < 8) {
        return "Get some more shut eye!";
    }
};
sleepCheck(10);
sleepCheck(5);
sleepCheck(8);


Thank you.


#2

Hi,

just remove the condition (numHours < 8) after "else" (this is not required her) and your code will run properly.

Check your corrected code:

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


#3

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

I can't figure out what I have done wrong. Thank you in advance for any help.


#4

Also, it cut off, but there is a v at the beginning of var


#5

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