Functions, return and if / else


#1


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


My code returns this error: SyntaxError: Unexpected token


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


#2

normally a function has opening and closing curly brackets:

var example = function(){

}

the {} are missing in your case


#3

Sorry, I'm not understanding this. I've modified code as follows with curly bracket after the function. What am I missing?

var sleepCheck = function (numHours);{
if (numHours >=8)

return "You are getting plenty of sleep! Maybe even too much!";}
else {
return "Get some more shut eye";}
sleepCheck (10);


#4

now the { of if is gone? add it, and your function doesn't have a closing curly bracket (})

uhm... your function declaration has a semi-colon, preventing the function from working properly

make sure to properly nest your if/else inside your function


#5

I must be dense. I'm still not understanding what you mean. Can you copy my code, insert the curly brackets where they belong so I can see what you mean? I understand the logic of the if/ else but getting the syntax right is proving difficult.


#6

you have a function:

var example = function(){

}

inside the function you nest a if/else:

var example = function(){
  if (condition){
  
  } else {

  }
}

that is it, simply nesting


#7

Got it! I see now what you mean. Thank you.


#8