File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments