Functions & if / else


#1

`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!";
};

console.log(sleepCheck(10));`

I've looked through this plenty of times and still can't seem to find the problem. It just states:
SyntaxError: Unexpected token


#2

Dont forget @alaanor its three ticks instead of one you put to organize your code. Anways ill find the problem soon


#3

Wow that was quick. You forgot to close your function. So you have to put a bracket between console.log() and the else statement


#4

Wait so like this; ?

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!";
}
}; //This is the extra bracket you told me to add.

console.log(sleepCheck(10));

Because it just states the same error: SyntaxError: Unexpected token


#5

Hey, I was just doing this lesson myself when I saw this post, after I did mine I had a look at yours and pasted it into my codeacademy page, I think its because of the semicolon you've got here: var sleepCheck = function (numHours); as well as the one you have in the middle of the if statement before else. Let me know if you get it working and leave either/both of those in cause so far I've been really bad at remembering to use semicolons so there may be something i didn't notice :slightly_smiling:


#6

Thanks, this worked. Semi Colons are hard to remember where to put and where not to!


#7

Yes after adding the closing } the problems are the semicolons. I've written a longer post about the one between if an else here:


and the {} after functions are just mandatory so there is nothing allowed between ) and { except whitespaces.
And about semicolons in general you might have a look at this blog post:
https://www.codecademy.com/blog/1707