Skip to content

Commit 2b7cc3b

Browse files
committed
Modified files for exercise TheOdinProject#5. Completed exercise TheOdinProject#5.
1 parent 81ce253 commit 2b7cc3b

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

05_sumAll/sumAll.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
1-
const sumAll = function() {
1+
const sumAll = function(start, end) {
2+
3+
//only number datatype
4+
if (typeof start !== 'number' || typeof end !== 'number') {
5+
return 'ERROR';
6+
}
7+
8+
//only positive number
9+
if (start < 0 || end < 0) {
10+
return 'ERROR';
11+
};
212

13+
if (start > end){
14+
startSum = end;
15+
endSum = start;
16+
17+
} else {
18+
startSum = start;
19+
endSum = end;
20+
}
21+
22+
sumNum = 0;
23+
24+
for (let num = startSum; num <= endSum; num++ ) {
25+
sumNum = sumNum + num;
26+
};
27+
28+
return sumNum;
329
};
430

531
// Do not edit below this line

05_sumAll/sumAll.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ describe('sumAll', () => {
44
test('sums numbers within the range', () => {
55
expect(sumAll(1, 4)).toEqual(10);
66
});
7-
test.skip('works with large numbers', () => {
7+
test('works with large numbers', () => {
88
expect(sumAll(1, 4000)).toEqual(8002000);
99
});
10-
test.skip('works with larger number first', () => {
10+
test('works with larger number first', () => {
1111
expect(sumAll(123, 1)).toEqual(7626);
1212
});
13-
test.skip('returns ERROR with negative numbers', () => {
13+
test('returns ERROR with negative numbers', () => {
1414
expect(sumAll(-10, 4)).toEqual('ERROR');
1515
});
16-
test.skip('returns ERROR with non-number parameters', () => {
16+
test('returns ERROR with non-number parameters', () => {
1717
expect(sumAll(10, "90")).toEqual('ERROR');
1818
});
19-
test.skip('returns ERROR with non-number parameters', () => {
19+
test('returns ERROR with non-number parameters', () => {
2020
expect(sumAll(10, [90, 1])).toEqual('ERROR');
2121
});
2222
});

0 commit comments

Comments
 (0)