//sample solution
function sum(n) {
/**Complete the code below to return the sum of
all the whole numbers from 1 to n. **/
var sumSoFar = 0; //Keep track of the sum so far
var currentNumber = 1;
while (currentNumber<=n) {
sumSoFar += currentNumber;
currentNumber += 1;
}
return sumSoFar;
}
//test
sum(10);
No comments:
Post a Comment