Hallo Zusammen,
ich als blutiger Anfänger, sitze schon seit Stunden vor folgender Aufgabe:
The program should take the user through the following process:
1. the customer is prompted to enter how many different products they want to purchase (you can assume the customer will input a whole number)
2. For each product, the customer is then prompted to
•enter the item number from the column headed Item in Figure 2, (e.g. they would enter 3 to choose product n-87-012)
•enter how many units of that product they require
(e.g. 6 Headbanger hi-fis).
3. Step 2 is then repeated until the number of products the user chose in Step 1 is reached. When the ordering process is complete, the program prints out the order.
Bisher habe ich folgendes erstellt, aber irgendwie bekomme ich den Output nicht hin.
var customerCodes = ['lt-17', 'gw-3', 'lg-9', 'il-77', 'fy-32'];
var customerPasswords = ['password', 'bluesky', 'dr45gr6', 'onlyme', 'lothlorien'];
// 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, 7, 60];
var productStock = [200, 0, 2, 500, 500, 15];
// These are useful variables
var customerIndex;
var password = "";
var found = false;
password = window.prompt("Please enter your password");
checkPassword();
// iterate over password array
function checkPassword()
{
for(var i = 0; i < customerPasswords.length && found == false; i++)
{
// check if password match
if(password == customerPasswords[i])
{
// remember customerIndex
customerIndex = i;
found = true;
}
}
if (found == true)
{
window.alert("Welcome, Customer " + customerCodes[customerIndex] + ". Ready to start shopping?");
}
else
{
window.alert("Wrong password");
password = window.prompt("Please enter your password");
checkPassword();
}
}
document.write("<BR>" + "<BR>" + "Here are the exciting products we have available today:");
document.write("<BR>" + "Item---Code--------Product-------------------Price- --Stock");
document.write("<BR>" + "=============================================" + "<BR>");
for (var j = 0; j < productCodes.length; j++)
{
document.write(j + "---" + productCodes[j] + "--" + productDescriptions[j] + "---" + productPrices[j] + "-- " + "--" + productStock[j] + "<BR>");
}
var numberOfProducts;
numberOfProducts = window.prompt("How many different products you want to purchase?");
var orderProductArray = new Array (numberOfProducts);
var orderQuantityArray = new Array(numberOfProducts);
var findProduct = new Array(numberOfProducts);
for (var k = 1; k <= numberOfProducts; k++)
{
orderProductArray[k] = window.prompt("Please enter the item number for product " + k + " you want to purchase");
orderQuantityArray[k] = window.prompt("How many units do you require for product " + k + " ?");
for (var r = 0; r < productCodes.length; r++)
{
if (productCodes[r] == orderProductArray[k])
{
findProduct[r] = r
}
}
}
document.write("<BR>" + "Here is your order il-77");
document.write("<BR>" + "Code--------Product------------------------Number----------Price Each");
document.write("<BR>" + "========================================");
for (var l = 1; l <= numberOfProducts.length; l++)
{
document.write("<BR>" + productCodes[findProduct] + "--" + productDescriptions[findProduct] + "-----" + orderQuantityArray[k] + "------------" + + productPrices[findProduct] + "<BR>");
}
Kann mir vielleicht jemand helfen und Licht ins Dunkel bringen?