DEV Community

Cover image for Multiples of 3 or 5
Panashe Tapera 💭
Panashe Tapera 💭

Posted on

Multiples of 3 or 5

I'm a web developer and I've been going through the problems at(https://projecteuler.net/problem=1).

I'm trying to get my coding skills better and think of better and faster algorithms.

While my solutions may not be the best there is, please be lenient when trying to improve my solution or offering alternative ones.

The problem is this:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Solution

let number1 = 0;
let number2 = 3;
let number3 = 5;

 for (let index = 0; index < 1000; index++) {
   if (index%number2 === 0 || index%number3 === 0 ) {
     number1 = number1 + index;
   };

 };
 console.log(number1);
Enter fullscreen mode Exit fullscreen mode

Discussion (0)