Ex2: if/else if/else - syntax error


#1


I am trying to find out what's wrong with my code. Console prints SyntaxError: Syntax error. There is something wrong with your syntax

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


#2

I think the order of your if and else if conditions may be wrong... You should have already had a previous code that said
var isEven = function(number) {
if(number % 2 === 0){
return true;
}
else{
return false
}
}

That's all from the previous lesson and it asks you to add onto your code, just asking you to add an else if statement using isNan.


#3

I changed it, but it still shows "syntax error":


#4

Remove the = sign. The equals sign is used as an assignment operator in javascript.


#5

it works. thank you.


#6

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