I'm doing this code:
Class Cash
{
constructor(v, q)
{
this.value = v;
this.quantity = q;
}
var money = [];
money.push( new Cash(50, 4);
money.push( new Cash(20, 4);
money.push( new Cash(10, 2);
i need to do this:
(money[0].value * money[0].quantity) + (money[1].value * money[1].quantity) + (money[n].value * money[n].quantity)
The expected result with the 3 arrays is 300 (50 * 4) + (20 * 4) + (10 * 2)
The idea is that no matter how many things i push into money it continues doing the sumproduct
I tried this, but doesn't work:
for (i = 0; i > money.length; i++)
{
(money[i].value * money[i].quantity) + (money[i++].value * money[i++].quantity)
}
Classshould beclass, there are three)and one}missing,>should be<and currently the sum is not stored anywhere. If you fix all that it should work.