I have an array that get the quantity of each product and I want to sum the numbers of them but when I use reduce it only put the numbers in array next to each other in red shopping button based on the picture!
This is my code:
function updateTotal() {
let total = 0;
let arr = [];
const items = document.querySelectorAll(".prodItem");
for (i = 0; i < items.length; i++) {
priceAmount = items[i].querySelectorAll(".prodPrice")[0];
productQuantity = items[i].querySelectorAll(".num")[0];
const quantity = productQuantity.value;
const priceContent = priceAmount.innerText;
const price = priceContent.replace("$", "");
total += price * quantity;
document.querySelector(".total-amount").innerText = "$" + total;
arr.push(quantity);
}
counter.innerText = arr.reduce(
(accumulator, currentValue) => accumulator + currentValue
);
}