If/else isEven vs number


#1

In the first exercise of More on Control Flow, I am curious why we have to use number rather than isEven to validate the if statement. if the variable isEven is equal to the function, shouldn't it recognize isEven as the number that is generated? I understand why using if(number%2) works, but why does if(isEven%2) NOT work?

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

#2

isEven is the function, right? And number is the parameter.

number is your input, and without first establishing if number % 2 === 0, you can't be sure if isEven is true. How can you use a null value to establish itself?

This seems vague as ■■■■, and if it is please let me know.
Hope I helped :slight_smile:


#3

Nah, I think it makes sense. Sometimes I forget that syntax is highly dependent on heuristics. Thank you! :slight_smile:


#4

Is that a psych101 word I hear?
haha, anyway, I'm glad I could help.


#5

It's actually a technically correct operational process analysis term to me lol Quite a useful word


#6

Hmm, I'm still learning... the best way to learn. Some of these lessons I get the answer quickly. Others, not so much.

I couldn't figure the answer to this one out and I resisted checking here until I really couldn't find the answer.

I was getting an error and I couldn't find it.

I checked here and the difference I had was this line

if(number%2 === 0)

I had

if (number%2 = 0)

This was obvious after I seen the correct way. I had learned about === in previous lessons.
When I was getting the error I began thinking maybe I have to do some more elaborate things and bring in more variables.

It turns out the answer was very simple. Hopefully this will get better with more practice and experience :slight_smile:


#7

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