-1
I’m a beginner in the world of programming and am doing my first projects in Javascript. I ran into this simple problem that I’m having trouble solving. I need a function that performs an operation at an undetermined amount of values. It does not necessarily have to be a multiplication, I would like to know for any operation (sum, subtraction, multiplication and division) how to create a function that calculates an indeterminate number of values that I pass. Always check the pre-determined amount of values. For example:
function mult (a,b) {
console.log (a * b)
}
mult (2,3)
In the above case I can only pass two values. If you pass 3, it will discard the third element.
I would like to do an undetermined amount of values, either by passing the mult ()
3 values or 10 values the function multiplies all. How can I do this?
Thank you very much. I did not know the variable Arguments and this new knowledge was extremely useful. I was able to use this method for multiplication and for summation. But it’s going wrong for division and subtractions. I’m breaking my head here.
– joaovmf