From 026eb4cd9144be5387fe20f6ebf22e6893f4a2ee Mon Sep 17 00:00:00 2001 From: Fredrik Uddenfeldt Date: Sun, 21 May 2023 20:25:32 +0200 Subject: [PATCH] passes 3/6 tests --- 05_sumAll/sumAll.js | 19 ++++++++++++------- 05_sumAll/sumAll.spec.js | 6 +++--- 2 files changed, 15 insertions(+), 10 deletions(-) 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'); }); });