What is wrong with my code?


#1

What is wrong with my code?? I'm on "More on Control Flow in JS" If/Else

var isEven = function(number)
{
if(isEven%2)
{
return true
}

else
{
return false
}

};


#2

Hey @usarowing,

In your if loop, you need to show which isEven%2 should equal to.

For example:

if(isEven%2===0){

:smiley:


#3

Hey @ragezapper thanks for the fast response I'm still a little bit confused :grimacing:


#4

Oops sorry I replied it to the wrong person. :sweat_smile: Or did I? I don't know lol. :smiley:

The thing is that you have to show which value it has to equal to, or else it won't make sense. If you just put this:

if(isEven%2){

There would be no requirement.

With the '===0' part, you are making a requirement for if isEven is used with a modulo by 2 and it equals 0.


#5

Oh right right wow I did not see that


#6

@ragezapper okay I understand what I did wrong but I don't understand how to get passed this part, I have tried so many different things and I always get some sort of error and for this one I get: "Oops, try again. Looks like your function returns false when number = 2. Check whether your code inside the if/else statement correctly returns true if the number it receives is even." Is there something I'm missing again?

var isEven = function(number)
{
if(isEven%2===0)
{
return true;
}

else
{
return false;
}

};


#7

You have to put your thing as the parameter number.

if(number%2===0){

That's why it doesn't work when number is 2. BECAUSE YOU DON'T USE IT!:smiley:


#8

@ragezapper wow I am honestly... I don't want to make excuses for how I missed that but I have been going at this all day and almost all day yesterday and it is currently 1:15am where I am so I'm pretty tired. I think that this is a sign that I should go to sleep and resume this in the morning. Thanks for all your help I really appreciate it.


#9

No problem, glad to help. :smiley: