5
I’m trying to do it like this:
if(i % 2){
console.log(i);
}
i is the variable is coming from a for loop.
Why isn’t it working?
5
I’m trying to do it like this:
if(i % 2){
console.log(i);
}
i is the variable is coming from a for loop.
Why isn’t it working?
7
You have to compare it with 0
to check if the rest of the division is zero, otherwise you are right:
if(i % 2 == 0){ console.log(i); }
for (let i = 0; i < 10; i++) {
console.log(i, i % 2 == 0 ? 'é par' : 'é ímpar')
}
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
Thanks, it worked.
– Seu Madruga