sleepCheck, Functions if/else


#1

I know people have written in on this one, but I'm having a hard time following people's comments on semicolons and it is confusing.

I not only get a syntax error but also something about a token else statement. Can anyone see where I went wrong? Thanks.

`// 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 do it correctly here:

console.log(sleepCheck(10));

the semi-colon is after the console.log, just like a semi-colon should be after a return statement:

return "something";

your semi-colon after the return statements are a bit off


#3

I am getting the correct output but the program does not allow me to continue. See screenshot below:


#4

@tagcoder71779
Your code is fine however it ask you to print out sleepCheck on a first time 10 hours, on a second time 5 hours and on a third time 8 hours. So when you're calling your function, it should look like this;
sleepCheck(10);
sleepCheck(5);
sleepCheck(8);


#5

The strings you return should be an exact match, you shot your eyes rather then shut your eyes (bad idea)


#6

Cool! Thanks so much!


#7

Hi I rewrote my code and checked semi colons and curly brackets carefully. However, I am still getting a syntax error referencing a problem with a {.
Does anyone see the error? Thanks. a little frustrating!

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

`
The error msg says to check the if/else statement and the comparison. And the editor is not printing out anything. I was using console.log() but thought that there were too many parenthesis with which I could err. Thanks.


#8

@mccbjnn
I think you should remove your semicolon when you finish creating your function in the }; before calling the functions. Hope this helped you.


#9

Gave that a try and I still got an error msg even after a refresh. I've looked at other people's codes for this and it is the same as mine....maybe I can try another browser.
But I want to spend some time on the rock paper scissors right now, thats hard to understand what to do in English logic. Thanks I will update when I change browsers.


#10

changing browser should work, the code you posted is fine


#11

I have no error but I believe my function call return only for the first sleepCheck...its not checking for 5 and 8 how to call/pass function values multiple times?

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


#12

return only returns, you can log what is returned by using console.log() on the function call:

console.log(sleepCheck(10));