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.tsx80 chars6 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