Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created November 10, 2011 17:21
Show Gist options
  • Save jakedobkin/1355477 to your computer and use it in GitHub Desktop.
Save jakedobkin/1355477 to your computer and use it in GitHub Desktop.
My First Javascript (Euler Problem 1)
<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>
@djacobs
Copy link

djacobs commented Nov 10, 2011

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment