## Project Euler 001 – JavaScript

5 02 2011

Problem 1

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.

Solution

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;

<title>Project Euler 001</title>

<body>

<script type="text/javascript">

//Add all the natural numbers below one

//thousand that are multiples of 3 or 5.

//this one is pretty similar to c#

for (three = 0; three < 1000; three += 3) { answer += three; }

for (five = 0; five < 1000; five += 5) { answer += five; }

for (fifteen = 0; fifteen < 1000; fifteen += 15)

{ answer -= fifteen; }

document.write("<b>" + answer + "</b>");

</script>

</body>

</html>

Discussion

Last solution of the week.    Nothing too special here.

If you have questions, leave a comment or find me on Twitter (@azzlsoft) or email (rich@azzlsoft.com).