Created
September 16, 2013 06:07
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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