Oops, try again. It looks like you didn't include your else if() branch


#1



2/14 More on Control Flow in JS


Oops, try again. It looks like you didn't include your else if() branch.


var isEven = function(number) {
    if (isNaN(number)) {
        console.log("invalid number")
    }
    else  {
        if (number % 2 === 0) {
        return true;
          }
        else { 
        return false;
        }
    }
};

console.log(isEven(370))


#2

HI the lesson want that you use if, else if and else statement


#3

Hello, thank you for your answer. Now it is ok. Buti have two more questions.(sorry , my english is not perfect :))
1)
Does it have no differance if i use the followng: else if (....) { ...} //and this// else { if (....) {....} }. i thought i must always use else with the brackets {}.
2)
and the second question

**
var isEven = function(number) {
if (number % 2 === 0) {
return true;
}
else if(isNaN(number)===false) {
return false;
}
else {
console.log("Invalid number");
}
};

console.log(isEven(370))
**
i get

true
Invalid number //why he strart using else if(isNaN(number)===false) {....

i thought he would stop after the first if (number % 2 === 0)


#4

(don't worry my english isn't perfect too)

  1. Does it have no differance if i use the followng: else if (....) { ...} //and this// else { if (....) {....} }

Yes it doesn't ..Your first code its fine .. it's just the lesson which want you to use the else if.

2 Invalid number //why he strart using else if(isNaN(number)===false) {....

its because you used console.log() instead of return, in a function when you use console.log() even if the condition is false it will be print

and it come from the else statement

else {
console.log("Invalid number");
}

#5

Thank you very much!:slight_smile: