1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 | // Do the Gaussian. Sum to 10 equals 55!
var sumThis = {
thesum: 0,
numbers: [ 1,2,3,4,5,6,7,8,9,10 ],
doIt: function() {
this.numbers.forEach(
function(number) {
this.thesum+=number;
}
,this);
}
}
sumThis.doIt();
document.write(sumThis.thesum);
Output
55
|