Why is this failing?


#1

i get the following error ..."Oops, try again. Make sure your if/else if/else statement returns a string when the function input isn't a number. " but my code does return a string. Am I misunderstanding the task?

var isEven = function(number) {
// Your code goes here!
var isItANumber = isNaN(number);

if (isItANumber) {console.log("this is not a number");}

else if (number % 2) { return false;}

else {return true;}

};
isEven("this is a string")


#2

The problem is in here:

You do not need this, so I suggest that you delete it. Also:

Since we deleted the isItANumber thing, we have to change this to:

if(isNaN(number)){

Because we are looking at if the parameter of number is not a number or is.

In here:

You need to say something like:

else if(number%2===0){

Because there's no requirement, really for that else if statement.:smiley:


#3

thanks for the quick reply, i have tidied up the code but it still fails with the same error

var isEven = function(number) {
if (isNaN(number)) {console.log("this is not a number");}
else if (number %2 === 0) { return true;}
else {return false;}
};
isEven("this is a string")

Oops, try again. Make sure your if/else if/else statement returns a string when the function input isn't a number.


#4

Read the "Oops, try again" thing again. It says that the if/else statement should return a string when the function isn't a number. This translates to that if the parameter number isNaN, it should return
a string. SO:

Look at the bolded parts of the if statement carefully....

Also:

Is Even must be put as a number so, change the isEven value into a number.:smiley:


#5

Sorry I don't understand, my function input isn't a number, its a string.......isEven("this is a string")
my if/else statement then returns true after evaluating the if statement...if (isNaN(number)).... it then writes a string ...."this is not a number".

From my perspective this fits the requirement ..

Make sure your if/else if/else statement returns a string when the function input isn't a number.

my input wasn't a number and the statement returned a string?


#6

Okay, never mind about changing the isEven thing. But you need to change your console.log into a return statement.


#7

that was it! thanks!