Introduction to Functions lesson 12


#1

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


SyntaxError: expected expression, got keyword 'if'


var sleepCheck = function(numHours)
if (sleepChe >= 8) {
  return("You're getting plenty of sleep! Maybe even too much!");
} else{
  return("Get some shut eye!");
} 
sleepCheck(10);

Second day of coding and I am stuck on this. This is the entire code. I am not sure why it is not working correctly so any ideas are appreciated.


#2

For the if part, it should say if (numHours >= 8), not if (sleepCheck >=8). sleepCheck is the function. The if part is trying to say if the value you assign to the parameter is greater than or equal to 8, then the message will be returned. The parameter for this function is numHours.


#3


Try to add an opening curly barcket { where the arrow is aiming.
And "sleepCheck(10);" replace it with a closing curly barcket and a semi-colon };


#4

Thanks to you both. I changed the if statement to use numHours and added the open curly bracket after (numHours). I added the closed curly bracket and semicolon after sleepCheck(10). That resolved it for me.


#5

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