Function and If/Else error


#1


https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/4?curriculum_id=506324b3a7dffd00020bf661


I write the code for testing Function with If/else condition. The console does behave as expected but i get the Syntax error.


// Write your function below. 
// Don't forget to call your function!
var sleepCheck= function(numHours){
  if (numHours >= 8 ) {
    return("You are getting plenty of sleep! May be even too much!");
  }  
  else {
      return("Get some more shut eye!");
  }
};
sleepCheck(10);


#2

The instructions want you to check for 5 and 8 hours as well. Also, try changing "May be" in your console log statement to "Maybe".


#3

Try to write this :

return "You're getting plenty of sleep! Maybe even too much!";

You have to write return without ().


#4

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


#5

Down below is copy paste of my code...it keeps displaying this error to me when i click submit code--> "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.""

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

Thank you i found my mistake it was (more shut eye!) and not (more shut eye) :slight_smile:


#9

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