Exercise 2, errors, even if the code does what expected


#1



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


Hi profis, here come the beginner with confusion and questions.
I try to learn this language (4 me new). Without interaction is very difficoult to reconize where the errors come from.
Instead a slution, i wish somebody could explain me where i'm wrong.
Thank ur support i'll keep coding :wink:


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


#2

isEven('kebab') --> false

If you look at your output, why is it talking about the letter U?
What does your line 3 do?
What type of value is isNaN? Is it meaningful to compare it to a number?

I suggest refreshing the page between runs because you assign to isNaN which can have side-effects to your next run. Your function isn't supposed to have side-effects. (in other words, you shouldn't assign to isNaN)


#3

In this exercise, you have to use the isNaN function as part of an else if condition to evaluate an input into the isEven function that is Not a Number. In your 2nd line, you seem to assign the value of "U" to isNaN. I'm not sure what happens if you give a variable the name of a function and try to run it as a function. Refer back to the instructions where you are shown examples of how the isNaN function takes and evaluates input.


#4

Hi Biff75, thank you one more time 4 ur support.
Actually i didn't knew that isNaN is a function, i've just followd the istructions on the left side in the execise page.
I'll keep trying until i make the code run correctly.

By the way i must say that without any knowledges in JavaScript, so easy is this Codecademy execises series not that much. I'm watching also others online courses to help me find the way.

Thks ones more


#5

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