Problem with Lesson 12 Functions & if / else


#1


Hello.

I have created code to solve the problem of Lesson 12.

When I execute the code I get the right answers on the window in the right, but without the quotation marks.

console.log(sleepCheck(10)) ---> You're getting plenty of sleep! Maybe even too much!

console.log(sleepCheck(5)) ---> Get some more shut eye|

console.log(sleepCheck(8)) ---> You're getting plenty of sleep! Maybe even too much!

However, an error message appears.

What is happening, is it a bug in the program or am I doing something wrong.

Please help me!

Error Message is; Oops, try again.
It looks like your function doesn't return "Get some more shut eye!"
when numHours is 5. Check your if / else syntax and whether you're
using the correct comparison operator.


The code that was used is

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

Hi there.

return("Get some more shut eye|");

I believe you may have accidentally used the wrong symbol after "eye". It's needs to be "eye!" (exclamation mark) not "eye|" (vertical bar). I have a feeling that this will solve your issue.


#3

Correct Answer would be as followed:

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

I was having issues getting mine to clear because in the first return statement after sleep! there is only one space between sleep! and Maybe instead of two spaces as you would expect.


#4

I guess it's worth mentioning that it's not entirely necessary to include parentheses around the strings after the return keywords.


#5

Yes.
You are completely right.
I have written it in the wrong way.
Problem Solved.
Thank You so much.


#6

ANSWER

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


#7

The space was my problem as well, thanks!


#8

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