in the html : <span class="cart-prize">30.00</span>
const total = [];
const items = document.querySelectorAll('.cart-prize'); //item price displaying on the cart when cart popups
items.forEach(function(item)
{
total.push(parseFloat(item.textContent)).toFixed(2);
});
const totalMoney = total.reduce((accumulator, EachArrayValue)
=> accumulator + EachArrayValue);
items.forEach((each) => each = "$"+ each.textContext);
document.getElementById("totalMoney").textContent =
"$"+totalMoney; //works ok
document.getElementById("itemTotal").textContent =
total.length + " items"; //works ok
after summing up all the price elements in the total array with the reduce method here I tried to concat "$" string with the each textcontent of "cart-prize":
items.forEach((each) => each = each.textContext + "$");
But not succeed.Only float numbers display on the cart without dollar sign
I couldn't figure out where I've made a mistake. Is there anthing wrong with this method : items.forEach((each) => each = "$" + each.textContext);
each? Should that not beeach.textContextto begin with …?eachin the left-hand side of the assignment ?