#12 If/Else


#1

Okay, Ive spent the last hour scouring this thread and trying every option I can find. I decided to take a break when I entered the exact code that someone else said had worked. If someone could take a look at it and help me out Id appreciate it. I`ve tried refreshing the browser and its still not working.

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

This is the error I`m receiving---
Oops, try again. It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!" when numHours is 10. Check your if / else syntax and whether you're using the correct comparison operator.


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

Here is the function I used, it worked for me...


#4

Yea, I'm getting that message too. ???

I cut and pasted the code from gracegool, which looks exactly the same as mine, and her's worked? Strange.

Keep hacking!


#5

thanks its working :slight_smile:


#6

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));
};
I'm having problems with with this code now I've written exactly the way they've taught me and still won't work. I keep getting the unexpected else error no matter what I do.


#7

Drop the {} around the console log and the console.logs

Try this:
// 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!";
}
};

sleepCheck(10);