let sum = 0;
function innerAdd(a,b){
sum = a + b;
console.log(sum);
}
innerAdd(5,5,25,25) // Still getting 10 as output
let sum = 0;
function innerAdd(a,b){
sum = a + b;
console.log(sum);
}
innerAdd(5,5,25,25) // Still getting 10 as output
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.