Output even numbers in the loop
importance: 5
Use the for loop to output even numbers from 2 to 10.
for (let i = 2; i <= 10; i++) {
if (i % 2 == 0) {
alert( i );
}
}
We use the “modulo” operator % to get the remainder and check for the evenness here.