I wrote a simple program for learning purposes recently that (for now) basically just adds all the numbers together. But, for some reason, when I try to call it ( the programm is a function ), it puts out an "maximum call stack size exceeded" error. Is there any way to fix it? The answer may be very obvious, but I'm a very beginner at this stuff. Here's the code:
var add = function(num1, num2, num3, num4, num5) {
for(i = 0; i < add.length; i++) {
if(i === 0) {
var first = add(i);
} else if(i === 1) {
var second = add(i);
} else if(i === 2) {
var third = add(i);
} else if(i === 3) {
var fourth = add(i);
} else if(i === 4) {
var fifth = add(i);
console.log(first + second + third + fourth + fifth);
};
};
};
add(1, 2, 3, 4, 5);