Can't see the probelm!


#1

Keep getting an '(' error, can some please point it out to me I'm stumped..

var isEven = function(number) {
// Your code goes here!

if (isNaN (number));
{
return "There's no numbers!";
}
if else(number%2===0)
{
return true;
}
else
{
return false;
}

};

Thanks!


#2

@boardplayer69886,

var isEven = function(number) {
// Your code goes here!

if (isNaN (number)) {
return "There's no numbers!";
}
else if (number%2===0) {
return true;
}
else {
return false;
}

};

console.log("isEven outcome for 2 is "+ isEven(2) );
console.log("isEven outcome for 3 is "+ isEven(3) );
console.log("isEven outcome for 'test'is "+isEven("test") );

//==>output:
isEven outcome for 2 is true
isEven outcome for 3 is false
isEven outcome for 'test'is There's no numbers!


#3

It's almost safe to say that we will rarely if ever see a semi-colon precede a code block. If one does, then the statement before has no bearing or attachment logically to the statements contained in the code block.

if (5 > 10);
{
    console.log("this happened all on its own.");
}

// this happened all on its own.

As we can see, the conditional has no bearing on the code that follows because the semi-colon told JavaScript that the statement had ended. The code that follows isn't parsed until the next line parse & execution cycle. The code block has no conditional, so it executes fine.


#4

Thanks for the example to follow. I caught the (if else ) mistake. If you learn code better by mistakes I'm on track to be a genius!


#5

Appreciate the tip, definitely gonna keep it in mind.