Functions & if/else


#1

I have read other posts and it still doesn't seem to work. Any assistance?

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


#2

You have a semicolon on the } of your else which should not be there. And you're missing the }; to close the function.


#3

That worked!

Thanks so much.
Judith


#4

I had the same problem - not closing the function....

I'm wondering if if you need to put () for the statement e.g is return ("bla bla") the same as return "bla bla" ... because it doesn't seem to make a difference but I always thought you had to use ().

Thanks


#5

return is a keyword and not a function so the () are not necessary. But you can almost everywhere add () then they work like the parentheses in math 2*(3+4). But as there is mostly only one value after return that is not necessary and too many () to cope is probably more confusing than helpful.