Skip to content

Commit 748fe65

Browse files
committed
Add function to calculate sum of multiples of 3 & 5
1 parent 0eaa931 commit 748fe65

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

sum_multiples_of_3_and_5.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6
2+
// and 9. The sum of these multiples is 23.
3+
// write a program that takes in an integer and prints sum of all the multiples of 3 or 5
4+
// below that integer.
5+
6+
const number = (input) => {
7+
let num = input;
8+
let sum = 0;
9+
for (let i = 0; i < num; i++) {
10+
if (i % 3 === 0 || i % 5 === 0) {
11+
sum += i;
12+
}
13+
} return sum;
14+
}
15+
console.log(number(10));

0 commit comments

Comments
 (0)