If/else if/else help


#1

I need help on this lesson. I don't know how to put the else if statement in my code. Am I doing it correctly? (And what about isNaN? Am I using that correctly?)


https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/0/2?curriculum_id=506324b3a7dffd00020bf661


The console says: SyntaxError: expected expression, got keyword 'else'

and the error message it gives me is: "Oops, try again. There was a problem with your syntax."


var isEven = function(number) {
  // Your code goes here!
  if (number%2===0) {
      return true;
  } else {
      return false;
  } else if (isNaN) {
      return "This is not a number!"
  }
 
};

What am I doing wrong? This is honestly very confusing to me. Any help would be appreciated. Thanks :slight_smile:


#2

you can't have a else if after an else, the order is:

if
else if
/* more else if if you want */
else

you can't have else after else if, since else is everything else, there is nothing after it


#3

Else is like default, and it goes down the list of else if to test all of it's options. It's like a list, and once it fits a category, (else), it will not continue to look for it's condition to agree with another statement.


#4

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