+ 1
Hi..could someone please explain to me how the EVEN values is achieved in the 'for loop'
6 Answers
+ 2
if divide by 2 == 0
even
else
odd
or the use of not
if /2 !=0
odd
else
even
checking one is kind of testing both like boolean. the for loop bit will just be traversing each item in the loop til
all are done lol
+ 1
var age =0;
for(;age<=40 ; age+=2){
document.write(age);
}
+ 1
Okay! Great thanks
+ 1
Irene Aruto that code will work, but a better way will be:
for (var n = 0; n <= 40; n++) {
if (n % 2 == 0) {
document.write(n)
}
}
see you code is only counting in twos, but if e.g the user entered a number and if its even you want to do A if odd do B
the above if statement will check if that input number is even or odd
0
please make a go at it first, write a code that showed you try, then we will help youđ
0
if something divides by 2 evenly no remainder its even if it does not divide by 2 evenly and had say a remainder 1 its odd