find sum of numbers divisible by 3 or 5 and print to page in javascript

index.tsx
let sum = 0;
for(let i = 1; i <= 100; i++){
  if(i % 3 === 0 || i % 5 === 0){
    sum += i;
  }
}
document.write("The sum of numbers divisible by 3 or 5 is: " + sum);
167 chars
8 lines

In this code block, we initialize a variable sum to 0. We then loop through numbers from 1 to 100 using a for loop. For each number, we use an if statement to check if it is divisible by 3 or 5 using the modulo operator. If it is, we add it to the sum variable using the addition assignment operator. Once the loop has finished, we use document.write() to print the sum to the page.

gistlibby LogSnag