odin-default-js-exercises/sumAll/sumAll.js

21 lines
302 B
JavaScript
Raw Normal View History

2017-11-20 19:51:01 +00:00
var sumAll = function(a, b) {
if (a > b) {
let temp = a
a = b
b = temp
}
if (
a < 0 || b < 0 ||
typeof a != 'number' || typeof b != 'number'
) {
return 'ERROR'
}
let sum = 0
for(let i = a; i < b + 1; i++) {
sum += i
}
return sum
2017-08-24 13:26:01 +00:00
}
module.exports = sumAll