M
Mark Scott
Hi
If I choose to buy one product the output is what I expect, ie the product
is listed. If I choose to buy more then one product, the output shows that
code and product are undefined? I am sure that the error is in the
section:
for (orderIndex = 0; orderIndex < purchaseCount; orderIndex = orderIndex +
1)
{
document.write
(productCodes[orderProductArray]+"-------"+productDescriptions[orderProductArray]+"--------"+orderQuantityArray[orderIndex]
+"<BR>")
}
but I am having a time trying to solve. any ideas?
Cheers
Mark
// These are arrays containing product data
var productCodes = ['a-23-009', 'k-246-07', 'd-555-01', 'n-87-012',
'u-521-08', 't-99-002'];
var productDescriptions = ['Superslurry electric blender', 'Apple - iPod
(second-hand)', 'CoziNap nylon duvet tog 2', 'Headbanger mini
hi-fi 20W', 'MagiBoot shoe cleaning kit', 'The PushmiPulu lawnmower'];
var productPrices = [45, 50, 15, 25, 75, 70];
var productStock = [200, 0, 2, 500, 500, 15];
// These are useful variables
var productIndex
document.write("Welcome, Customer. Ready to start shopping?<BR>")
document.write("<BR>Here are the exciting products we have available
today:<BR>")
document.write ("=========================================<BR>")
document.write("Item---Code--------Product-------------------------Price---Stock<BR>") for (productIndex = 0; productIndex < productCodes.length; productIndex =productIndex + 1){ document.write(productIndex+"---"+productCodes[productIndex]+"------"+productDescriptions[productIndex]+"-----"+productPrices[productIndex]+"---"+productStock[productIndex]+"<BR>")}var purchase, purchaseCount, orderIndexpurchaseCount = window.prompt ("Please enter the number of differentproducts you wish to purchase today:","")var orderProductArray = new Array(purchaseCount)var orderQuantityArray = new Array(purchaseCount)for (var purchase = 0; purchase < purchaseCount; purchase = purchase + 1){ orderProductArray[purchase] = window.prompt("Please Enter the ProductCode","") orderQuantityArray[purchase] = window.prompt("Please Enter theQuantity","")}document.write ("<BR>Here is your order <BR>")document.write("Code--------Product------------------------Number----------PriceEach<BR>")document.write ("=========================================<BR>")for (orderIndex = 0; orderIndex < purchaseCount; orderIndex = orderIndex +1){document.write(productCodes[orderProductArray]+"-------"+productDescriptions[orderProductArray]+"--------"+orderQuantityArray[orderIndex]+"<BR>")}
If I choose to buy one product the output is what I expect, ie the product
is listed. If I choose to buy more then one product, the output shows that
code and product are undefined? I am sure that the error is in the
section:
for (orderIndex = 0; orderIndex < purchaseCount; orderIndex = orderIndex +
1)
{
document.write
(productCodes[orderProductArray]+"-------"+productDescriptions[orderProductArray]+"--------"+orderQuantityArray[orderIndex]
+"<BR>")
}
but I am having a time trying to solve. any ideas?
Cheers
Mark
// These are arrays containing product data
var productCodes = ['a-23-009', 'k-246-07', 'd-555-01', 'n-87-012',
'u-521-08', 't-99-002'];
var productDescriptions = ['Superslurry electric blender', 'Apple - iPod
(second-hand)', 'CoziNap nylon duvet tog 2', 'Headbanger mini
hi-fi 20W', 'MagiBoot shoe cleaning kit', 'The PushmiPulu lawnmower'];
var productPrices = [45, 50, 15, 25, 75, 70];
var productStock = [200, 0, 2, 500, 500, 15];
// These are useful variables
var productIndex
document.write("Welcome, Customer. Ready to start shopping?<BR>")
document.write("<BR>Here are the exciting products we have available
today:<BR>")
document.write ("=========================================<BR>")
document.write("Item---Code--------Product-------------------------Price---Stock<BR>") for (productIndex = 0; productIndex < productCodes.length; productIndex =productIndex + 1){ document.write(productIndex+"---"+productCodes[productIndex]+"------"+productDescriptions[productIndex]+"-----"+productPrices[productIndex]+"---"+productStock[productIndex]+"<BR>")}var purchase, purchaseCount, orderIndexpurchaseCount = window.prompt ("Please enter the number of differentproducts you wish to purchase today:","")var orderProductArray = new Array(purchaseCount)var orderQuantityArray = new Array(purchaseCount)for (var purchase = 0; purchase < purchaseCount; purchase = purchase + 1){ orderProductArray[purchase] = window.prompt("Please Enter the ProductCode","") orderQuantityArray[purchase] = window.prompt("Please Enter theQuantity","")}document.write ("<BR>Here is your order <BR>")document.write("Code--------Product------------------------Number----------PriceEach<BR>")document.write ("=========================================<BR>")for (orderIndex = 0; orderIndex < purchaseCount; orderIndex = orderIndex +1){document.write(productCodes[orderProductArray]+"-------"+productDescriptions[orderProductArray]+"--------"+orderQuantityArray[orderIndex]+"<BR>")}