Skip to content

Commit

Permalink
Problem 1 with function
Browse files Browse the repository at this point in the history
  • Loading branch information
goformarty committed Mar 2, 2017
1 parent 0fb6661 commit 5c638b0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions problem1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Problem 1: Multiples of 3 and 5
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. */

var sum = 0;
var array = [];

for (i=1; i<1000; i++) {
if (i%3 === 0 || i%5 === 0) {
sum += i;
array.push(i);
function solution1(number){
var sum = 0;
for(var i = 1;i< number; i++){
if(i % 3 == 0 || i % 5 == 0){
sum += i
}
}
return sum;
}

console.log("All natural numbers below 1000 that are multiples of 3 or 5 are: " + array);
console.log("The sum of these multiples is: " + sum);
solution1(1000);

0 comments on commit 5c638b0

Please sign in to comment.