-
Notifications
You must be signed in to change notification settings - Fork 91
/
Simple Adding
29 lines (25 loc) · 1.69 KB
/
Simple Adding
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/***************************************************************************************
* *
* CODERBYTE BEGINNER CHALLENGE *
* *
* Simple Adding *
* Using the JavaScript language, have the function SimpleAdding(num) add up all the *
* numbers from 1 to num. For the test cases, the parameter num will be any number *
* from 1 to 1000. *
* *
* SOLUTION *
* This is a simple iterative function that add each number in sequence. *
* *
* Steps for solution *
* 1) Set var tot to 0. *
* 2) Loop from 1 to num and add i by tot to get new tot. *
* 3) Return tot for answer. *
* *
***************************************************************************************/
function SimpleAdding(num) {
var tot = 0;
for (var i = 1; i <= num; i++) {
tot += i;
}
return tot;
}