12 Functions & if else unexpected token else


#1

Here is my 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);

it comes back with an "unexpected token else".

any help?


#2

When you make your function as a variable then you need to end it with semicolon.

var testFunction = function(){
    do something;
};

#3

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));
console.log(sleepCheck(5));
console.log(sleepcheck(8));

and what about my code, it returnes with "ReferenceError: sleepcheck is not defined"
I checked it in JS Fiddle and it validates.


#4

When you look closely it says "sleepcheck" is not defined, the "C" is not capitalized. :relaxed:


#5

Thank you very much!