 # 2. If/Else If/ Else

ReferenceError: isEven is not defined
ReferenceError: Invalid left-hand side in assignment

how do I fix my coding the log true?

var isEven = function(number) {
if(9 + 10 = 21){
return false
} else if (9 + 10 = 19) {
return true
} else {
return unknown
};

Your function’s name suggests that it should determine whether a number is even (divisible by the number 2)

Currently it does not do anything with its argument, so it will not be able to determine whether that’s the case

Also note that `=` is the assignment operator, whereas you appear to by trying to use it to test whether two values are equal.

2 Likes

You’re missing a closing parenthesis `}` at the end as well.

2 Likes

here’s the message i am getting now

Oops, try again. Looks like your function returns false when number = 3. Check whether your code inside the if/else statement correctly returns true if the number it receives is odd.

and here is the fixedish code

var isEven = function(number) {
if(9 + 10 === 21){
return false
} else if (9 + 10 === 19) {
return true
} else {
return unknown
}
};

You seem to have ignored this part that @ionatan has mentioned.

You have an input variable called `number` in your function call. Why are you not using that?

4 Likes

i don’t know what he meant when he said that

Your error suggest that if number = 3, your function should output true. Hence you are validating whether your `number` input located in your function definition `var isEven = function(number) {` is odd or even.
If it is odd, return true. If it is even, return false.

You can use the modulo `%` to help you. Modulo gives you the remainder. You can check whether the modulo, when divided by 2, will give you 0 (number is even) or 1 (number is odd).

``````4 % 2 == 0 # 4 divided by 2 has a remainder of 0
3 % 2 == 1 # 3 divided by 2 has a remainder of 1
``````
3 Likes

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

Help please  var isEven = function(number) {
if(4 % 2 == 0){
return true
} else if (3 % 2 == 1) {
return true
} else {
return true
}
};

Like I said, use `number`, your parameter(argument), for your function in your if statements.
Right now, you are always returning true because your first if statement is always true regardless of input (`4 % 2 === 0` is always true).

For example:

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

Think about it. What’s the purpose of this function? To see if certain numbers are even. Why evaluate only 4 and 3 when you need to evaluate ANY number? What do you use if you want to evaluate ANY number but don’t want to update multiple things manually? You use a variable and here, you have a variable called `number` which you seem to be ignoring.

3 Likes

so I past the first part, now here is what I’m getting.

Oops, try again. It looks like you have a ReferenceError! Maybe you deleted isEven?

and here is the code for that error

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

What are you trying to do here?
You don’t have a case where the number is odd.
The function is supposed to return true if `number` is even and false if `number` is odd. Or is there something else that states to return walrus (which you never defined).

2 Likes

yah. the last one. I tried to make it a joke. but then I changed it to this

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

and the console says that the last else is a syntax error

Not a very good joke ``````} else if (isNaN = false)
return true
}
``````

What’s this for? I don’t think you need this.

2 Likes

With the walrus thing, I wanted to see if that would work.

also, did you not see what I changed the title to?

Well…you’ve never defined what a walrus is so it didn’t work.

Are you able to provide me the link to the lesson you are on? I finished the old javascript course and they may have moved things around. I’m not too sure what the instructions are (and they are usually very specific).

2 Likes

I see now. `IsNaN` needs an input to be evaluated. Should be `IsNan(number)`. If you want to compare, you don’t use `=` but `==`.

the function should return a string that tells the user that their input isn’t a number. (This string can say whatever you like.)

Seems like you’re also skipping over this instruction.

2 Likes