Unexpected identifier?


#1

var sleepCheck = function(numHours) {
if numHours >= 8 {
return "You are getting plenty of sleep ! Maybe even too much !";
} else numHours <= 8 {
return "Get some more shut eye !";
};

sleepCheck(10);

Hello my fellow programming buddies .... can you see what I can't ? :slightly_smiling:


#2

well, the condition of a if statement should be inside brackets:

if (condition) {/* whatever you want to happen if condition is true */}

else can't have a condition at all, since it runs if everything else fails. And your function is missing a closing curly bracket (}), the opening bracket doesn't match to any closing bracket


#3

Hey stetim94,

yeah ... I edited my code so it looks like this now:

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

I'm still getting error .... :-/


#4

That looks better. but still no brackets around the condition in the if statement:

if numHours >= 8 {

should be:

if (numHours >= 8) {

Exactly, which exercise is this so i can run it?


#5

JS 12. Functions & if / else

Tried put condition in parentheses but still not getting far ....


#6

The string returned should be an exact match, do i need to find all the differences? I spotted a few


#7

Well ... now I'm getting this:

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.

In preview I'm getting what I'm supposed to get but still getting this pop-up about comparison ...


#8

By now you made a couple of changes, could you post an updated version of your code?


#9

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


#10

When i said exact match, i meant it. Inside your if condition, you have You are instead or You're, a space between sleep and !, same fore much and ! (spaces shouldn't be there)

then in else, you have a space between eye and ! which should be there. I recommend to copy the strings from the instructions.


#11

Yeah ... I removed extra spaces in strings and passed !

Bloody spaces ! Apparently Codecademy makes assignments "gap-sensitive".

Thank you buddy ! Appreciate your time !