Skip to content

Instantly share code, notes, and snippets.

@NEbere NEbere/sum.js
Created Feb 2, 2016

Embed
What would you like to do?
Calculates the sum of 1 to 1000, if the number is a multiple of 5 or three,double it and add it to the sum.
$(document).ready(function(){
var sum1= 0, res = 0, totalSum = 0;
for (var x = 1; x <= 1000; x++)
{
if (x % 3 === 0 || x % 5 === 0)
{
k = x * 2;
sum1 += k;
}
res += x;
}
totalSum = res + sum1;
alert(totalSum);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.