Why is it saying else is an unexpected token?


#1


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


I am getting a syntax error saying that there is an: unexpected token else.


    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

There is a semicolon before your else statement. Semicolon use is tricky. Here's a link that may come in handy on that topic:

https://www.codecademy.com/blog/78


#3

Thank you, it works now, and the guide really helps me understand semicolons better.


#4

Yeah, it'd be nice if they went over stuff like that before lessons, glad it helped :slight_smile:


#5

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