-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsumMultiple.js
More file actions
36 lines (31 loc) · 1.01 KB
/
sumMultiple.js
File metadata and controls
36 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Create a function with a limit parameter
// The function should return
// the sum of the muliples of 3 & 5 from 0 up to the limit passed
let sumMultiple = 0;
let multiplearray = [];
function sum(limit){
for(let i = 0; i<=limit; i++){
if ((i % 3 === 0) || (i % 5 === 0)){
multiplearray.push(i)
}
}
console.log(multiplearray)
for(let i = 0; i<multiplearray.length; i++){
sumMultiple += multiplearray[i];
}
console.log(sumMultiple)
}
sum(10)
// This problem was a little tasking
// Mosh's way was much shorter and precise
// but i used this cause i wanted it to be clear
// the first loop takes the multiples and puts them inside an array using the push method
//While the second loop adds the element in the array
// Mosh Hamedani's Solution
// function sum(limit){
// let sum = 0;
// for (let i = 0; i <= limit; i++)
// if ((i % 3 === 0) || (i % 5 === 0))
// sum+= i;
// return sum;
// }