Introduction to Functions lesson 12


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

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.


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.


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


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.


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