Even numbers from 100 to 1[solved]

//doesn't work
 for (var i=100; i<=0; i--)
  {
     if(i % 2 === 0) 
     {
       console.log(i);
     }
   } 

BUT
//this works
    for (var i=0; i<=100; i++)
     {
      if(i % 2 === 0) 
       {
          console.log(i);
        }
     }

why

no need for if conditions just decrement i by 2 and it will run

1 Like

that isn’t working as well

you didnt use the proper condition.
i<=0 means it takes -ve value.
use greater symbol.

keep i>0 in the conditional statements

1 Like

thanks. didn’t see that

1 Like
var e = 100;
for (e=100; e>=1; e--) {
    if(e%2==0) {
        console.log(e);
    }
}

This should work

1 Like

i>0 use this because you are using i<=0 it comes out of the loop it is not executed

1 Like