Created
November 10, 2011 17:21
-
-
Save jakedobkin/1355477 to your computer and use it in GitHub Desktop.
My First Javascript (Euler Problem 1)
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
<html> | |
<body> | |
<script type="text/javascript"> | |
t= 0; | |
for (i=0;i<1000;i++) | |
{ | |
m = i%3; | |
n = i%5; | |
if (m==0 || n==0){ | |
t+=i; | |
} | |
} | |
document.write(t); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a way to eliminate the need for the m & n variables:
t=0;
for (i=0;i<1000;i++)
{
if ((!(i%3)) || (!(i%5))) { t+=i; }
}
document.write(t);