Oops, try again. Your function returns true for 3!


#1

var isNumberorNot = function(input) {
// Your code goes here!
if(isNaN(input)) {
return "This is not a number.";
}

else if (input % 2 === 0) {
return "This is even.";
}

else {
return "This is odd.";
}

};

isNumberorNot("What is wrong?");


#2

I'm not entirely sure which question you are on, but by the look of your code it seems that its asking you to return a Boolean value(true or false), whereas you are turning strings("even and "odd"). Your code should look like this.

var number = 0


var isEven = function(input) {
    if (input % 2){
        return;
    }
    else if (isNAN(input)) {
        return true;
        }
        else{
    return false;
    }
  
};
isEven(3);

If that solved it and helped you please mark my reply as the solution.


#3

Hi, I used your code, and if I change 3 to 4 for the argument: isEven(4);

It shows me this error message:

Oops, try again. It looks like you have an error in your code! See the error message for more details: ReferenceError: isNAN is not defined


#4

Hmm, it may have something to do with the question, could you please copy and paste the url of the question you are on. Then copy and paste you code so we can try and solve it.


#5

https://www.codecademy.com/en/courses/javascript-beginner-en-qDwp0/0/2?curriculum_id=506324b3a7dffd00020bf661

var number = 0;

var isEven = function(input) {
if (input % 2){
return "-------------";
}
else if (isNAN(input)) {
return true;
}
else{
return false;
}

};
isEven(4);

I just changed the argument from 3 to 4.


#6

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