-3
let sum = 0;
function innerAdd(a,b){
    sum = a + b;
    console.log(sum);
}

innerAdd(5,5,25,25) // Still getting 10 as output

  • 2
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 30 '22 at 17:47
  • 1
    `5 + 5` is `10`. Why would you expect anything different? – VLAZ Mar 30 '22 at 17:47
  • 1
    Why would you expect to get something other than 10 when you are adding 5 and 5? – Quentin Mar 30 '22 at 17:48

1 Answers1

-1

Javascript only recognizes the first two values. if you want to be able to add more values you will have to add a for() cycle. something like this:

function sum() {
  var total = 0;
  for (var i = 0; i < arguments.length; i++) {
    total += arguments[i];
  }

  alert(total);
}

sum(1,2,3,4);

this way you can add any number of parameters, sum(5,5,25,25) will be 60.