If/Else if


#1

Hello can anyone see what is wrong with this code?

var isEven = function(number) {
  // Your code goes here!
  if (number % 2 === 0){
  return true;
    }
    else if (isNan(number)){
        return "numberless flavour";
    }
    
    else {
        return false;
    }
};
isEven(Math.floor(Math.random()*8));

Saying syntax error at the moment. We dont have to directly assign a value to number do we?
I assume its only an issue with the isNaN since didnt have issue in last part of the lesson


#2

Your else if block,

should check for true,

else if (isNaN(number) === true) {


#3

bandit, that is not true? isNaN will return true if it is not a number, which means the if condition will evaluate to true, even if you don't compare it with true

@peroxis, isNaN should have a uppercase N at the end, not a lowercase


#4

yep that worked thanks. glad that was the problem less confusing for my logic


#5

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