1/14 if/else


#1

I can't understand what the error is in this statement.
It would be really helpful if somebody could explain to me what the error is.
Here is the statement:
var isEven = function(number) {
if(number%2===0){
return "true";
}
else{
return "false";
}

}
isEven(3)


#2

Hey @killerstealer365! Its just that you only need two equal signs!

Like this:

 if(number%2==0){

instead of your code:

  if(number%2===0){

Hope this helped if it didnt please respond saying so!


#3

Sure, i will try it out.


#4

It did not work but thanks for trying to help.


#5

Oh ok i spoted the problem! Your suppose to have it in CHAR. Meaning dont return the string , return the char.

So your Code:

Correct Code:

if(number%2==0){
return 'true'
}
else{
return 'false'
}

Hope it helped! If it didnt please reply saying so!


#6

I found the mistake.It is actually:
if(number%2===0
){
return true;
}else
{
return false;
}
see the difference but thanks anyway


#7

JS treats '' and "" the same way also char (in other languages) would always be a single character.
And the difference between == and === is that both compare the values but === additionally checks the types.


#8

Yea sorry, i really confuse Java and JavaScript! But i will stop from now onwards!