odin-javascript-exercises/05_sumAll/sumAll.js

19 lines
404 B
JavaScript
Raw Normal View History

2023-06-19 16:12:59 -07:00
const sumAll = function (number1, number2) {
if (number1 < 0 || number2 < 0) return 'ERROR'
if (typeof number1 !== 'number' || typeof number2 !== 'number') return 'ERROR'
2023-06-19 16:12:59 -07:00
let sum = 0
const start = Math.min(number1, number2)
const end = Math.max(number1, number2)
for (let i = start; i <= end; i++) {
sum += i
}
return sum
}
2017-08-24 06:26:01 -07:00
// Do not edit below this line
2023-06-19 16:12:59 -07:00
module.exports = sumAll