12 if/else is not working


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


#2

I'm not sure what your problem is. I just ran the code and it works fine. can you send a link to the assignment? it might have to do with the instructions.


#3

if the error code says something like "You didn't return 'get some more sleep'. chances are that you just need to copy and paste the text from the instructions. if its not that then ill need to see the assignment to tell you more.


#4

I'm having the exact same issue. The error I'm getting is:

"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."


#5

SleepCheck is a function name, numHours is the parameter for the function.
so, if you want to use parameter inside the function (inside the curly bracket), you have to take the parameter which is numHours in your exercise.
var sleepCheck = function (numHours)
{
if (numHours >= 8) {

but when you want to call the function, call the function name which is sleepCheck.
ex. sleepCheck();


#6

your code looks fine. whats error are you getting?


#7

that should be if(numHours >= 8)


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.