I am working on a coding exercise for freeCodeCamp. The purpose of the exercise is to take an array as input that contains 2 numbers. It should return the sum of those two numbers and all numbers between them.
I tried writing a simple for loop using Math.min(), and Math.max() as parameters, but somehow my funtion always returns 0. The basic logic is for the for loop to start at the lowest number in the array, then increment by 1 until it gets to the biggest number in the array, and always add the number to the output variable.
function sumAll(arr) {
var outcome = 0;
for(var x = Math.min(arr); x<Math.max(arr); x++) {
outcome += x;
}
return outcome;
}
sumAll([1, 4]);
Any help is appreciated.
Math.minandMath.maxwrong. See the docs: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… and developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/….