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
This commit is contained in:
Isah Jacob 2022-10-30 22:27:03 +01:00
parent 9583f5d564
commit a72813e9c4
1 changed files with 20 additions and 2 deletions

View File

@ -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;