Question
the code below is supposed to keep track of your items as you shop. the items, quantity, and cost are stored in seperate arrays that
the code below is supposed to keep track of your items as you shop. the items, quantity, and cost are stored in seperate arrays that should be printed out in a table. i am not sure where i am going wrong with printing the arrays into tables. any help would be appreciated!
var itemsArray = []; // declares the array
var costArray = [];
var quantityArray = [];
function insertItem(){
itemsArray.push(document.getElementById('item').value); // inserts at end
costArray.push(document.getElementById('cost').value); // inserts at end
quantityArray.push(document.getElementById('quantity').value); // inserts at end
}
function deleteLast(){
itemsArray.pop();
costArray.pop();
quantityArray.pop(); // deletes from end
}
function deleteFirst(){
itemsArray.shift();
costsArray.shift();
quantityArray.shift(); // deletes from end
}
function displayReceipt(){
var table = document.createElement("table");
text="";
text="==============================================";
text+="
Mini-Mart EMU Receipt: Jessica Harris
";text+="
- ";
for (var i = 0; i < itemsArray.length; i++) {
var row = table.insertRow(i);
var tempItem = document.createTextNode(item[i]);
var tempQuant = document.createTextNode(quantity[i]);
var tempCost = document.createTextNode(cost[i]);
var itemCell = row.insertCell(0);
var quantityCell = row.insertCell(1);
var costCell = row.insertCell(2);
itemCell.appendChild(tempItem);
quantityCell.appendChild(tempQuant);
costCell.appendChild(tempCost);
}
text += "
document.getElementById("demo4").innerHTML = text;
}
function getTotal(){
}
Enter an item into the text box. It stores it into an array.