If / else - help me



the code below is worked , 1stly -- why i hve to use 'isNaN' ?. Even it is not in the instructon.

2ndly - kindly anybody explain the star marked line ?

var isEven = function(number){
if (number % 2 === 0){
return true;
*else if (isNaN(number)){
*return "This is not a number";
else {
return false;


isNan is a method in Javascript used to check if a value is an integer or not. :slight_smile:


want to know it according to instruction , if possible , kindly tell me .


What do you mean, as in what it's doing in your code?


i hve the correct code , bt want to understand something.

in the instruction isNaN is not given , why we use that ?


You use it to check if the argument given in the function call is a number if I call and print out your function for example with a string,


it should return,

"This is not a number"


can't understand , would u tell me another way plz


Sure :slight_smile: Okay imagine you want to call and print out your function isEven with the number 8 you would write,


This will print out true to the intepreter because your if condition checks if a number is even and returns the boolean true if it is.

Now, if you were to call and print your function with a data type that is not an integer for example a string,

console.log(isEven("I am a string"))

Your code will return,

This is not a number

Because of your else if condition.

Otherwise your code will returnfalse if the argument called with your function is invalid.

I hope you understand clearly now. :grin:


yap , thank you , now i understand


Awesome! you're welcome. :slight_smile:


last question -- kindly tell me this basic format about bracket ?

bracket within bracket .



Those are actually parentheses () and why they have to be to is because one is need for your else if condition so,

else if (condition)

and one is needed because isNan is a javascript method,



else if (isNan(argument)) //Clsoses both the else if condition and JS method


i got it , tnx 4 ur explanation ,


if i remove the last line 'isEven(6);' the code also works , how it works ?
var isEven = function(number){
if (number % 2 === 0){
return true;

else if (isNaN(number)){
return "This is not a number";
else {
return false;



anybody tell me plz .


i think the program isn't checking to see if you called the function. it just wants to see that you wrote the "else if" statement correctly. :slight_smile:


understand that , thank u , hope we will meet again :slight_smile:


var isEven = function(number) {
// Your code goes here!
return true;
return false;


is it worked ?............................................


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