Hi, I'm learning Javascript and I've come across this:
var depositos=[];
var nro,monto;
do {
nro=prompt('Ingrese nro de cliente','');
nro=parseInt(nro)
if (nro!=0)
{
monto=prompt('Ingrese monto a depositar','');
monto=parseInt(monto);
depositos[nro]=monto;
}
} while (nro!=0);
var suma=0;
var canti=0;
for(var f=0;f<depositos.length;f++)
{
if (depositos[f]!==undefined)
{
suma=suma+depositos[f];
canti++;
}
}
document.write('Cantidad de depósitos:'+canti+'<br>');
document.write('Total depositado por todos los clientes:'+suma);
Basically what it does is request a customer value that will be used as the index of the array and an amount to deposit that will be the value of that index, to show them with document.write the total of deposits and the total of the amounts deposited, the program ends by entering a 0 in the client number. My problem is that I do not know how to do the following:
1) That if, when entering the same client number for the same time the same index of the array, instead of replacing the old index value of the array with the new one, the old value is added with the new value , because if for the second time I enter the same client number (index of the array), and enter a new value different from the previous one, this index value is replaced by the new one, what should I do?
2) The same with the amount of deposits, it happens to me that if in the first and second time I put the same index (client number), I only count 1 deposit independently that the values are different.