Okay I’m not wanting anyone to do my HW so please don’t lecture me. I just don’t even understand what the hell I am supposed to do. Maybe someone can break it down for me? LOL
Question states:
A mail order house sells five different products whose retail prices are: product 1- $2.98, product 2 $4.50, product 3- $9.98, product 4- $4.49, and product 5- $6.87. Write a script that reads a series of pairs of numbers as follows:
a) Product Number
b) Quantity sold for one day
Your program should use a switch structure to help determine the retail price for each product. Your program should calculate and output HTML that displays the total retail value of all products sold last week. Use a prompt dialog to obtain the product number from the user. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results.
Oh! Silly me. Since it tells you to use a switch structure, you don't need an array or object. The label associated with each case statement is a product ID and then do perform some action, e.g. set a variable, in the code block for each case.[/QUOTE]
[code=php]<HTML>
<!-- Sierra Bass -->
<!-- Section 01 -->
<!-- Due 9.20.06 -->
<HEAD>
<TITLE>Exercise 15.12</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
var product, // Product number entered by user
quantity, // Number of items sold entered by user
price, // Price of each product
totalprice, // The total for all products sold
validInput = true; // Indicates if input is valid
//User inputs product number and quantity sold
product = window.prompt( "Enter product number:", "1" );
quantity = window.prompt( "Enter number of items sold:", "1" );
//Switch multiple-selection structure
switch ( product ) {
case "1":
price: "2.98"
break;
case "2":
price: "4.50"
break;
case "3":
price: "9.98"
break;
case "4":
price: "4.49"
break;
case "5":
price: "6.87"
break;
default:
validInput = false;
}
// Calculate products sold
totalprice = product*quantity
// To show
if ( validInput == true ) {
document.write("The total retail value of all
product " + product + "'s sold last week is: $" + totalprice);
}
else
document.writeln( "Invalid choice: " + product );
</SCRIPT>
</HEAD>
<BODY>
<P>Click Refresh (or Reload) to run the script again</P>
</BODY>
</HTML>
[/code]
[code=php]<HTML>
<!-- Sierra Bass -->
<!-- Section 01 -->
<!-- Due 9.20.06 -->
<HEAD>
<TITLE>Exercise 15.12</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
var product, // Product number entered by user
quantity, // Number of items sold entered by user
price, // Price of each product
totalprice, // The total for all products sold
totalCounter, // Total for the week
validInput = true; // Indicates if input is valid
// Initialization phase
total = 0; // clear total
totalCounter = 0; // prepare to loop
//User inputs product number and quantity sold
product = window.prompt( "Enter product number, -1 to quit:", "1" );
quantity = window.prompt( "Enter number of items sold:", "1" );
//Switch multiple-selection structure
switch ( product ) {
case "1":
price: "2.98"
break;
case "2":
price: "4.50"
break;
case "3":
price: "9.98"
break;
case "4":
price: "4.49"
break;
case "5":
price: "6.87"
break;
default:
validInput = false;
}
// Calculate products sold
while (product != -1){
for (var t = 1; t<=5; t++);
}
// Show results:
if ( validInput == true ) {
document.write("The total retail value of all
product " + product + "'s sold last week is: $" + totalprice);
}
else
document.writeln( "Invalid choice: " + product );
</SCRIPT>
</HEAD>
<BODY>
<P>Click Refresh (or Reload) to run the script again</P>
</BODY>
</HTML>
[/code]
we have to have a loop so they can enter each product number in and how many of each product[/QUOTE]
the prof. tells us to test in IE[/QUOTE]
[code=php]<HTML>
<!-- Sierra Bass -->
<!-- Section 01 -->
<!-- Due 9.20.06 -->
<HEAD>
<TITLE>Exercise 15.12</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
var product, // Product number entered by user
quantity, // Number of items sold entered by user
price, // Price of each product
totalprice, // The total for all products sold
totalCounter, // Total for the week
validInput = true; // Indicates if input is valid
// Initialization phase
total = 0; // clear total
totalCounter = 0; // prepare to loop
//User inputs product number and quantity sold
product = window.prompt( "Enter product number, -1 to quit: ", "1" );
quantity = window.prompt( "Enter number of items sold:", "1" );
//Switch multiple-selection structure
switch ( product ) {
case "1":
price = "2.98"
break;
case "2":
price = "4.50"
break;
case "3":
price = "9.98"
break;
case "4":
price = "4.49"
break;
case "5":
price = "6.87"
break;
default:
validInput = false;
}
// Calculate products sold
if (product != -1){
totalprice = product*quantity;
}
// Show results:
if ( validInput == true ) {
document.write("The total retail value of all product's sold last week is: $" + totalprice);
}
else
document.writeln( "Invalid choice: " + product );
</SCRIPT>
</HEAD>
<BODY>
<P>Click Refresh (or Reload) to run the script again</P>
</BODY>
</HTML>
[/code]
[code=php]<HTML>
<!-- Sierra Bass -->
<!-- Section 01 -->
<!-- Due 9.20.06 -->
<HEAD>
<TITLE>Exercise 15.12</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
var product, // Product number entered by user
quantity, // Number of items sold entered by user
price, // Price of each product
totalprice, // The total for all products sold
totalCounter, // Total for the week
validInput = true; // Indicates if input is valid
// Initialization phase
total = 0; // clear total
totalCounter = 0; // prepare to loop
//User inputs product number and quantity sold
product = window.prompt( "Enter product number, -1 to quit: ", "1" );
quantity = window.prompt( "Enter number of items sold:", "1" );
//Switch multiple-selection structure
switch ( product ) {
case "1":
price = "2.98"
break;
case "2":
price = "4.50"
break;
case "3":
price = "9.98"
break;
case "4":
price = "4.49"
break;
case "5":
price = "6.87"
break;
default:
validInput = false;
}
// Calculate products sold
if (product != -1){
totalprice = product*quantity;
}
// Show results:
if ( validInput == true ) {
document.write("The total retail value of all product's sold last week is: $" + totalprice);
}
else
document.writeln( "Invalid choice: " + product );
</SCRIPT>
</HEAD>
<BODY>
<P>Click Refresh (or Reload) to run the script again</P>
</BODY>
</HTML>
[/code]
[/QUOTE]
[CODE] totalprice = product*quantity;[/CODE]
This will just multiply the item code by the quantity[code=php]<HTML>
<!-- Sierra Bass -->
<!-- Section 01 -->
<!-- Due 9.20.06 -->
<HEAD>
<TITLE>Exercise 15.12</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
var product, // Product number entered by user
quantity, // Number of items sold entered by user
price, // Price of each product
total, // Sum of all products sold
totalCounter, // Total for the week
validInput = true; // Indicates if input is valid
// Initialization phase
total = 0; // clear total
totalCounter = 0; // prepare to loop
//User inputs product number and quantity sold
product = window.prompt( "Enter product number, or -1 to quit: ", "1" );
quantity = parseInt (window.prompt( "Enter number of items sold:", "1" ));
// Calculate products sold
while (product != -1){
total = product*quantity;
totalCounter =totalCounter + 1;
quantity = parseInt (window.prompt(
"Enter number of items sold:", "1" ));
}
//Switch multiple-selection structure
switch ( product ) {
case "1":
price = "2.98"
break;
case "2":
price = "4.50"
break;
case "3":
price = "9.98"
break;
case "4":
price = "4.49"
break;
case "5":
price = "6.87"
break;
default:
validInput = false;
}
// Show results:
if ( validInput == true ) {
document.write("The total retail value of all product's sold last week is: $" + total);
}
else
document.writeln( "Invalid choice: " + product );
</SCRIPT>
</HEAD>
<BODY>
<P>Click Refresh (or Reload) to run the script again</P>
</BODY>
</HTML>
[/code]
I can't get it to stop prompting now.. hahaThat's because nothing within your loop will change the test condition. You don't need that section of code inside a loop.
[/QUOTE]
while (product != -1){
total = product*quantity;
totalCounter =totalCounter + 1;
quantity = parseInt (window.prompt(
"Enter number of items sold:", "1" ));
}
0.1.9 — BETA 5.18