2/9 isEven if/e;se


#1

var isEven = function (number) {
if (number%2 === 0)
{ return true}
else if (isNaN(number))
{console.log("That is not a number.");}
else {return false}
};
isEven(4)

I cannot for the life of me see what is going wrong. I am getting the Oops! message. Also, when I enter string I get the "that is not a number message" twice. When I input a number I get the correct true/false return, but I also get the "That is not a number." message


#2

replace console.log with return
if you get error, please insert here link of course or instructions


#8

Critical comments ahead...

  1. Give all }'s their own line. Don't end lines with them.
  2. Give a statement its own line. Don't lead it with {.
  3. There are four semi-colons requred in this code. One in each branch statement, and one at the end of the function exrpression (which you have, already).

This function gives predictable results that are fixed to specific criteria for each case. There are three possible outcomes. The outcome is deterministic, based on the inputs.

We can structure our code to read like an essay if we give our code objects some breathing room, consistent placement and syntax, and we block consistently.

var foo = function ( arg ) {
    if ( arg_expression ) {
        return true;
    }
    else if ( arg_expression ) {
        return // ...;
    }
    else {
        return // ...;
    }
};

The structure of the code reveals its many colors, at a glance. White space is free. We can use as much of it as we need to reveal nesting levels and enclosure..