function sum(start, end) { return (start + end) * (end - start + 1) * .5 } alert(sum(1, 4)); //1 + 2 + 3 + 4 = 10 alert(sum(2, 5)); //2 + 3 + 4 + 5 = 14