使用Codecademy JS课程('迄今为止的故事:If,Else和Loops' 2/14)

时间:2015-05-23 19:32:54

标签: javascript

试用此代码

var isEven = function(number) {


    if (number % 2 === 0) {
        return true;
    } else if (isNaN(number)) {
        return "Not a number";
    } else {
        return false;
    }
}


isEven();

这一定对你有用。我得到这个正确!!!!

4 个答案:

答案 0 :(得分:2)

您获得ReferenceError,因为没有isNan功能。它被称为isNaN

答案 1 :(得分:0)

var isEven = function(number) {

  if (number % 2 === 0) {
      return true;

    } else if (NaN(number)) {
        return "Your input is not a number!";

    } else {
        return false;
    }
};

答案 2 :(得分:0)

var isEven = function(number) {
  // Your code goes here!
  if(number%2){
      return true;
  }
  else if(isNan (number)){
      return "Your input is not a number.";
  }
  else{
      return false;
  }
};`enter code here`

答案 3 :(得分:0)

检查出来:

var isEven = function(number) {
   if (isNaN (number)) {
      return "The input was not a number!";
   }  
   else if (number % 2 === 0) {
      return true;
   } 
   else if (isNaN (number) === true) {
      return "Your input isn't a number!";
     }
   else {
      return false;
      }
   };