Skip to content

Instantly share code, notes, and snippets.

@vasco3
Created September 16, 2013 06:07
Show Gist options
  • Save vasco3/6577129 to your computer and use it in GitHub Desktop.
Save vasco3/6577129 to your computer and use it in GitHub Desktop.
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.
/*
euler
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.
*/
//loop through each number until reaching naturalNumberQty
function sumMultiplesOf3And5(naturalNumberQty){
sumOfMultiples = 0;
for (var i = 1 ; i < naturalNumberQty ; i++) {
//test if i % 5 === 0 || i % 3 === 0
//if true then sum to the acumulator
if( i % 5 === 0 || i % 3 === 0 ){ sumOfMultiples += i }
};
//return acumulator
return sumOfMultiples;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment