Hi, I am building a basic shopping basket and the problem I find is that all the products, even with quantity of 0 are being displayed in the shopping basket. Please can anyone help!.. I don't know what I'm doing wrong. Thank you so much in advance!
This is my code:
function displayProducts(){
var quant = new Array (10);
quant[1] = Number(getInput("prodA"));
quant[2] = Number(getInput("prodB"));
quant[3] = Number(getInput("prodC"));
quant[4] = Number(getInput("prodD"));
quant[5] = Number(getInput("prodE"));
quant[6] = Number(getInput("prodF"));
quant[7] = Number(getInput("prodG"));
quant[8] = Number(getInput("prodH"));
quant[9] = Number(getInput("prodI"));
quant[10] = Number(getInput("prodJ"));
var nameArray = new Array (name1, name2, name3, name4, name5, name6, name7, name8, name9, name10);
var name1 = 'prodA';
var name2 = 'prodB';
var name3 = 'prodC';
var name4 = 'prodD';
var name5 = 'prodE';
var name6 = 'prodFi';
var name7 = 'prodG';
var name8 = 'prodH';
var name9 = 'prodI';
var name10 = 'prodJ';
for( var i=0; i<10; i++)
{
if (quant[i] > 0)
{
var product1 = quant[1] + ' ' + name1 + '</br>';
var product2 = quant[2] + ' ' + name2 + '</br>';
var product3 = quant[3] + ' ' + name3 + '</br>';
var product4 = quant[4] + ' ' + name4 + '</br>';
var product5 = quant[5] + ' ' + name5 + '</br>';
var product6 = quant[6] + ' ' + name6 + '</br>';
var product7 = quant[7] + ' ' + name7 + '</br>';
var product8 = quant[8] + ' ' + name8 + '</br>';
var product9 = quant[9] + ' ' + name9 + '</br>';
var product10 = quant[10] + ' ' + name10 + '</br>';
document.getElementById('shoppingBox').innerHTML = product1 + product2 + product3 + product4 + product5 + product6 + product7 + product8 + product9 + product10;
}
}
}