diff --git a/05_sumAll/sumAll.js b/05_sumAll/sumAll.js index a9479e2..32f8f67 100644 --- a/05_sumAll/sumAll.js +++ b/05_sumAll/sumAll.js @@ -1,19 +1,24 @@ const sumAll = function(x, y) { let theSum; - for (let i = x+1; i <=y; i++) { - theSum = x += i - } - return theSum + if (x < 0 || y < 0) {return('ERROR')} + + else + { - if (x | y <0 ) {return('ERROR')} + for (let i = x+1; i <=y; i++) { + theSum = x += i + + + + } + return theSum + } }; -// Need to add conditions for ERROR-message - // Do not edit below this line module.exports = sumAll; diff --git a/05_sumAll/sumAll.spec.js b/05_sumAll/sumAll.spec.js index ecb9fc3..a171e5f 100644 --- a/05_sumAll/sumAll.spec.js +++ b/05_sumAll/sumAll.spec.js @@ -7,16 +7,16 @@ describe('sumAll', () => { test('works with large numbers', () => { expect(sumAll(1, 4000)).toEqual(8002000); }); - test.skip('works with larger number first', () => { + test('works with larger number first', () => { expect(sumAll(123, 1)).toEqual(7626); }); test('returns ERROR with negative numbers', () => { expect(sumAll(-10, 4)).toEqual('ERROR'); }); - test.skip('returns ERROR with non-number parameters', () => { + test('returns ERROR with non-number parameters', () => { expect(sumAll(10, "90")).toEqual('ERROR'); }); - test.skip('returns ERROR with non-number parameters', () => { + test('returns ERROR with non-number parameters', () => { expect(sumAll(10, [90, 1])).toEqual('ERROR'); }); });