Quotes help make search much faster. Example: "Practice Makes Perfect"

Friday, December 7, 2012

LearnStreet Javascript Lesson 6 Exercise 1


//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


This is an example of scrolling text using Javascript.

Popular Posts