Return a string error (I'm returning a string)


#1


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


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


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


#2

Hi @jake.32,

If it may help please see the code sample below.
For this exercise try altering your logic a little, partially it would be constructed slightly more efficiently and more readable, if you omitted the first else if, but also because sometimes CC can be a little finicky anyway :slight_smile:

In this case then, note the exercise is asking for an IF / ELSE IF / ELSE... that's the key here, where as you have supplied IF / ELSE IF / ELSE IF.

var isEven = function(number) 
{
  // Your code goes here!  
  if (number % 2 === 0)
  {
    return(true);  
  }
  else if (isNaN(number))
  {
    return("Please enter only integer values");  
  }
  else
  {
      return(false);
  }
};

isEven("a");

#3

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