9. More control doesn't work


#1


var didgit = 36;
var isEven = function(didgit) {
  // Your code goes here!
  if(didgit%2===0){
      return true;
  }else if(isNan){
      return false;
  }
};
isNan('berry');


#2

Correct usage:

if (isNaN(x)) {
    return "Not a Number";
}

A digit is a single number character. 9 is a digit. 99 is not. To give your variables meaning that the reading can relate to, be sure to use correct terminology.

var isEven = function (x) {

};

Be sure to call the function,

isEven(36);

#3

Now it's saying that it can't find the variable "isNaN"


#4

what would go in the "else if" statement?


#5

That would be,

else if (isNaN(x)) {

}

x is where your variable goes.


#6

ReferenceError: Can't find variable: x
Is "x" the variable "digit", or "isEven", or is it just "x"?


#7

Please post what code you have so far.


#8

var didgit = 36
var isEven = function(didgit) {
// Your code goes here!
if(didgit%2===0){
return true;
}else if(isNaN(x));{
return false;
}
};


#9

x is not defined. Use your parameter variable in place of x.


#10

Now it says this needs to return a string:

var didgit = 36
var isEven = function(didgit) {
// Your code goes here!
if(didgit%2===0){
return true;
}else if(isNaN(isEven));{
return false;
}
};

Thanks man, by the way.


#11

Let's change the parameter name, so it makes sense to the reader...

var isEven = function (number) {
    if (number % 2 === 0) {
        return true;
    else if (isNaN(number)) {
        return "Not a Number";    // the expected string
    } else {
        return false;
    }
}

Be careful not to use the function name as a variable in the function.


#12

Thanks! That worked!


#13

Be sure to study the code, match it to the instructions, and practice by doing this exercise from scratch a couple of times. Do the typing so your muscle memory develops along with the concepts.


#14

Okay! Will do! Thank you!


#15

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