Skip to content

Commit 09efc4b

Browse files
committed
Create Simple Adding
1 parent d9bb7b5 commit 09efc4b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Simple Adding

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

0 commit comments

Comments
 (0)