I'm trying to do this:
if(i % 2){
console.log(i);
}
i is the variable of is coming from a for loop.
Why is not it working?
I'm trying to do this:
if(i % 2){
console.log(i);
}
i is the variable of is coming from a for loop.
Why is not it working?
You have to compare with 0
to check if the rest of the division is zero, otherwise it's right:
if(i % 2 == 0){ console.log(i); }
for (let i = 0; i < 10; i++) {
console.log(i, i % 2 == 0 ? 'é par' : 'é ímpar')
}