print the numbers from 1 to 100, but only print the even numbers in javascript

You can use a for loop to iterate through the numbers from 1 to 100 and a condition with the modulo operator % to check if each number is even before printing it. Here's the code:

index.tsx
for (let i = 1; i <= 100; i++) {
  if (i % 2 === 0) {
    console.log(i);
  }
}
80 chars
6 lines

This will print the even numbers from 2 to 100 in the console. The % operator returns the remainder of the division between two numbers, so if a number is even it should have a remainder of 0 when divided by 2.

gistlibby LogSnag