-3
What’s up with you guys? I have a shopping list and would like to multiply the quantity of the product with its value thus returning the result and add all the results.
I have already managed to do this, the problem is being to make with various products it is only multiplying all the values at once, I need help.
var quant = document.querySelectorAll(".quant");
var preco = document.querySelectorAll(".preco");
var total = 1;
for (var i = 0; i < quant.length && i < preco.length; i++)
{
total*= Number(quant[i].innerHTML) * parseFloat(preco[i].innerHTML.toString().replace(",","."));
document.querySelector(".valor").innerHTML = total.toString().replace(".",",");
}
<body>
<table id="tabela" border="1px">
<tr>
<td>Produto</td>
<td>Quant</td>
<td>Preço</td>
<td>Valor Total</td>
</tr>
<tr>
<td>Stawka</td>
<td class="quant">3</td>
<td class="preco">30,50</td>
<td class="valor"></td>
</tr>
<tr>
<td>Stawka</td>
<td class="quant">5</td>
<td class="preco">25</td>
<td class="valor"></td>
</tr>
</table>
</body>
Thank you very, very much, it’s been a long time
– Sapinn