Else/else if /else./more on control flow/ Stuck


#1

Why does it output the string "You input is not a number" two times??

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

 else {
     return false;
     }

};

isEven("me");


#2

Hi the isNaN should be like that
else if (isNaN(number)) { return "You didn't put a number!" }


#3

I know that but why does it write the sentence 2 times when I put control.log (shouldn't it write just one time)??


#4

I think that's because you call it at the end isEven("me");


#5

You can test if it's something other than your code causing the print, by adding a print that marks the end of when your code runs.

console.log("=== Any prints below this one is none of my doing ===");

#6

That and also I think because console.log() will always print out the string even if the condition is not true. So when the condition is true it prints the string the times (command console.log() and because of the function).


#7

Thanks guys for the help I got it now and @ionatan thanks for the tip :smile: