Created
July 12, 2013 09:23
-
-
Save atushi/5983087 to your computer and use it in GitHub Desktop.
Project Euler . 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.
This file contains hidden or 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
var TARGETNUM = 1000; | |
var i = 1; | |
var answer = 0; | |
while (true) { | |
flag = false; | |
if (TARGETNUM <= i) break; | |
if ((i%3==0) && (!flag)) { answer = answer + i; flag = true; } | |
if ((i%5==0) && (!flag)) { answer = answer + i; flag = true; } | |
i++; | |
} | |
console.log(answer); |
Author
atushi
commented
Jul 12, 2013
var sum = 0;
for (var i = 3; i < 1000; i++){
if ((i % 3) == 0) {
sum = sum + i;
} else if ((i % 5) == 0) {
sum = sum + i;
}
}
alert(sum);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment