Я новичок в js и имею тележку в веб-магазине, который я делаю для назначения Javascript, и я не могу заставить свою общую цену работать, которая отображается на веб-странице, когда пользователь нажимает на элементы, которые нужно добавить в корзину. Вот мой массив элементов, любая помощь будет признателен, спасибоJavascript, как я могу рассчитать общую цену в массиве элементов?
var cart;
var items = new Array(); //create array to store items
items[0] = "Greatest Hits CD", 10;
items[1] = "Girls CD", 10;
items[2] = "Shirt1", 20;
items[3] = "Mask Tee", 20;
items[4] = "Crewneck", 25;
items[5] = "Tour Poster", 9;
и вот моя функция
this.display = function() {
this.holder.innerHTML = "";
this.totalprice = 0;
for (var i=0; i<this.quantities.length; i++) {
if (this.quantities[i] > 0) {
this.totalprice += this.quantities[i]*this.items[i];
var elm = document.createElement('div');
elm.innerHTML = "<span class='name'>"+this.items[i]+" \</span><span class='quantity'>Quantity: "+this.quantities[i]+"</span>";
this.holder.insertBefore(elm, null);
}
}
var elm = document.createElement('div');
elm.innerHTML = "<span class='price'>Total Price: $"+this.totalprice+" </span>";
this.holder.insertBefore(elm, null);
document.getElementById('quantities').value = cart.quantities;
document.getElementById('items').value = cart.items;
}
вы не то, что Ассинг, что вы ожидаете с 'пунктов [0] = «Greatest Hits CD», 10; «лучше использовать» элементы [0] = [«Greatest Hits CD», 10]; ', массив, а не только онемение er, в результате работы с запятой. –