From a72813e9c47fc6a7a1b553f19c391233845f75f5 Mon Sep 17 00:00:00 2001 From: Isah Jacob Date: Sun, 30 Oct 2022 22:27:03 +0100 Subject: [PATCH] If statement to check lowInteger and highInteger are numbers using Number object to represent them as a Number also I used isInteger boolean condition to check that lowInteger and highInteger is an integer that return an error an if statement to check that lowInteger and highInteger returns error if they are less than zoro then if lowInteger is greater than highInteger then assign lowInteger to a temperary holder variable then assign value of lowInteger to highInteger then return the value of temperary holder back to highInteger create a variable that holds the final sumAll loop through the lowInteger and assign the final value to finalSum then return finalSum --- 05_sumAll/sumAll.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/05_sumAll/sumAll.js b/05_sumAll/sumAll.js index 00880c7..86c34bd 100644 --- a/05_sumAll/sumAll.js +++ b/05_sumAll/sumAll.js @@ -1,6 +1,24 @@ -const sumAll = function() { +const sumAll = function(highInteger, lowInteger) { + if (!Number.isInteger(lowInteger) || !Number.isInteger(highInteger))return "ERROR"; + if (lowInteger < 0 || highInteger < 0) return "ERROR"; + if (lowInteger > highInteger){ + const temp_holder = lowInteger; + lowInteger = highInteger; + highInteger = temp_holder + } + let finalSum = 0; + for (let integers = lowInteger; integers <= highInteger; integers++){ + finalSum += integers; + } + return finalSum; + }; - +sumAll(1, 4) +sumAll(1, 4000) +sumAll(123, 1) +sumAll(-10, 4) +sumAll(10, "90") +sumAll(10, [90, 1]) // Do not edit below this line module.exports = sumAll;