If/else


#1



// 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 pf sleep! Maybe even too much!";
};
    else {
      return "Get some more shut eye"; 
    };
};
sleepCheck(10);
sleepCheeck(5);
sleepCheck(8); 

it keeps saying 
syntax error,unexpected token


#2

If I run it locally:

$ node beta.js 
/tmp/js/beta.js:7
    else {
    ^^^^
SyntaxError: Unexpected token else

#3

When closing if statement you shouldn't put a semi colon. Should just be }


#4

even when i remove it, the feedabck is the same..


#5

else is expected as an optional component of an if-statement, so if an else is unexpected, then what precedes it is something other than if (condition) statement <else goes here>


#6

When I remove the semi-colon, they tell me

ReferenceError: sleepCheeck is not defined


#7

See how you spelt them


#8

the feedback is just 'unexpected token'

nothing about the 'if/else' statement..


#9

here my code after all the correction

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

but still, the feedback is staying the same


#10

The error messages here are far less verbose than they could be. I suggest running code in another interpreter if you need a line number or it looks like the error message isn't complete in some other way.
You can use nodejs, your browser (firefox shift+f4, idk about others, might need to use files), or some online js interpreter.

Alternatively, you can temporarily remove parts to narrow down the source of the syntax error. That's certainly not the easiest way to go about things though.


#11

Are you getting anywhere with that other interpreter and its error messages?


#12

I am getting this when I remove the semi-colon after the 'if' statement

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.


#13

That's something you can verify and follow up on


#14

Yes
But i don't see any mistake


#15

Well, then look. Find out. There's no substitute.

var result = sleepCheck(5);
console.log('sleepCheck(5) returns: ' + result);

And then if that does indeed not return what it should, then add more prints in the function to find out where it goes wrong.

If it seems to return the correct value, then you might have misunderstood what the return value is supposed to be. It could for example mean you have a typo.