I have a problem in 9. More on control Flow - 1. if /else


#1

Can anybody tell me how to pass this. If can write down an example, I will be very thankful.


#2

@gigablaster70715
Can we have your code and details from the exercise please? That will be very helpful if we want to understand your problem.


#3

this is what i am getting


#4

@limitless24
Here, you are trying to use the modulo on the function isEven you are creating. In the instructions, it tells you to test if the number put in parameter when you will call the function is evenly divisible by 2. So instead of isEven inside of your if statement, write number(which is the parameter the user needs to input to test whether the number is evenly divisible by 2) instead of isEven. Hope this helped you.


#5

thank you that was it


#6

In addition to this number%2 would give you a value of 0 or 1, so 0 is equivalent to false and 1 to true which is kind of contradicting towards what the exercise expects to see for even and odd numbers. So instead of relying on those side effect values better check for number%2 === 0 instead. Hope this is not too confusing.


#7


I have the same message all the time when I put an odd or even number when I call the function


#8

Hi a number is even if the remain of is division is equal to 0 when it is divide by 2 so your if condition should be like that

if (number % 2 === 0)

You should use % which gave the remain of the division .


#9

Thanks ! (I thought it was the same , evenly divisible by 2 = divisible by 2 ) .


#10

Sry for the late response just to make this clear:

dividing by 2 would e.g. for 3/2 yield 1.5 which is a number > 0 and as you can read here:
http://www.sitepoint.com/javascript-truthy-falsy/
All numbers except 0 are treated as true when used in a condition. So this might explain the problem, does it?
On the other hand % gives you the remainder of a division e.g. 5%2 is 2 because you can fit 2 whole 2s in 5 and a remainder of 1 as you cannot fit 2 in 1 using integers. So what you get from 5%2 is the remainder of 1.


#11

It says I got the lesson correct, because I followed the advice of these columns, but it isn't returning anything like it should be.


#12

My syntax:

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

};


#13

Any ideas on how to fix this?


#14

Hi try to call the function isEven with a number


#15

thanks! it worked! I may be able to remember that for next time.


#16

Also, this syntax is apparently not working even though I followed the directions:
link: https://www.codecademy.com/en/courses/javascript-beginner-en-qDwp0/0/2?curriculum_id=506324b3a7dffd00020bf661


#17

can you post your code ?


#18

Wow, the way you wrote your code was so cool. hahahahahaha


#19

Thanks so much! It was getting insanely frustrating!
Couldn't figure it out for the life of me....