Melonsmiller
10-28-2003, 10:24 AM
I know this is ridiculous, but I am taking a computer apps class and cant do the assignment. I have already bought over $180 in Javascript books and had the page changed by friends who supposedly knew what they were doing, but nothings helped. I thought maybe someone out there could help me. I am pasting the assignment and my solution that doesn't work. SOMEONE PLEASE HELP.
ASSIGNMENT: (There are 2 parts, but its mailny the 2nd assignment im having trouble with. I did the first one, and it worked, but then i toggled with it for the second assignment and now i cant get either to work)
ASSIGNMENT 1:
Your program needs to ask the user how many of each type of system will be built, calculate the total number of each type of component needed, and output a summary on the page. Using HTML and JavaScript only, and not a web editor, do the following:
Create an HTML document with a head, a title and a body. Make the title JavaScript Assignment 1.
In the body, display a welcome message like "Welcome to the configuration calculator!"
Write a JavaScript program that does the following:
Using the prompt() method, ask the user for the number of each type of system to be built (Home PC, Gamer PC, Business PC, and Power User PC). Save each of the answers in a separate variable. You will need to use a separate prompt for each value.
When the user has entered all the data, use the confirm method to display the values entered, and ask the user if they are all OK. Use only a single confirm to display all the values! (You can assume the user will click OK. You do not need to write code to handle a case where the user clicks cancel instead of OK. That will be next week's assignment.)
Calculate the number of each component needed by taking the number of each type of system times the number of that component required for that type of system for all the types of systems. For example, an order for 1 Home PC, 0 Gamer PCs, 3 Business PCs, and 2 Power User PCs would need 6 CD/RW drives ( (1 * 1) + (0 * 0) + (3 * 1) + (2 * 1) ) == 6 . Do this for each of the components (Motherboard, RAM module, CD/RW drive, and DVD drive), and save each result in a separate variable.
Use the document.write method to display on the web page the results of the calculations. Your output should look like: For __ Home PCs, __ Gamer PCs, __ Business PCs, and __ Power User PCs, you will need to order:
__ Motherboard(s)
__ RAM Module(s)
__ CD/RW drive(s)
__ DVD drive(s)
Where the __ indicates where your computed values should go.
ASSIGNMENT #2:
For assignment, you will need the HTML/JavaScript program that you created last week for the JavaScript 1 project (PC Integrators). You will expand the program to include some conditional branching.
1. Open the text document of your solution to the PC Integrators problem.
2. You used a confirm method to display the number ordered of each system. The program assumed the user would press OK in the confirm box. Add an IF statement to the program that will display an alert box containing an error message, if the user presses CANCEL instead of OK. The message should advise the user to reload the page and re-enter the data.
3. Now add an ELSE/ IF structure, based on this data: If a customer orders more than 4 Home PC units, or more than 3 Gamer PC units, the customer qualifies for a 5% discount. If a customer orders 5 Business PC units, or any Power User units, that customer will qualify for a 10% discount. Otherwise the customer does not qualify for any discount. You want to have an ALERT box displayed if the customer qualifies for a discount ("Customer will receive a __ % discount."). If the customer does not qualify for a discount, use document.write to display the text "No discounts apply." You are required to use the ELSE/IF. You will also need to refer to your Boolean logical operators.
MY INCORRECT SOLUTION:
<html>
<head>
<title>JavaScript Assignment 1</title>
<body><h1 align="center"><font face="impact">Welcome to the configuration calculator!</h1>
<script language="Javascript">
document.write
var bc;
var gc;
var pu;
var bgh;
bc = prompt ("How many business computers would you like built?");
gc = prompt ("How many gaming computers would you like built?");
pu = prompt ("How many power user computers would you like built?");
bgh = prompt ("How many home computers would you like built?");
var confrim = confirm("You ordered " +bc+" business computers, " +gc+" gaming computers, " +pu+" power user computers, and " +bgh+" home computers");
var mb;
var mb = ((bc * 1) + (gc * 1) + (pu * 1) + (bgh * 1));
var ram = ((bc * 1) + (gc * 1) + (pu * 1) + (bgh * 1));
var dvd = ((bc * 1) + (gc * 1) + (pu * 1) + (bgh * 1));
var cdrw = ((bc * 1) + (gc * 1) + (pu * 1) + (bgh * 1));
document.write("You ordered " +bc+" Business Computers, " +gc+" Gaming Computers, " +pu+" Power User Computers, and " +bgh+" Home Computers. For this, you will need to order:<br>");
document.write( +mb+ " motherboards<br>");
document.write( +ram+ " ram modules<br>");
document.write( +cdrw+ " cd/rw drives<br>");
document.write( +dvd+ " dvd drives<br>");
if ((bgh>4)||(gc>3))
{
window.alert("You receive a 5% discount");
}
else if ((bc==5)||(pu>0));
{window.alert("You receive a 10% discount");
}
else
{window.alert("No discounts apply");
}
</script>
</html>
ASSIGNMENT: (There are 2 parts, but its mailny the 2nd assignment im having trouble with. I did the first one, and it worked, but then i toggled with it for the second assignment and now i cant get either to work)
ASSIGNMENT 1:
Your program needs to ask the user how many of each type of system will be built, calculate the total number of each type of component needed, and output a summary on the page. Using HTML and JavaScript only, and not a web editor, do the following:
Create an HTML document with a head, a title and a body. Make the title JavaScript Assignment 1.
In the body, display a welcome message like "Welcome to the configuration calculator!"
Write a JavaScript program that does the following:
Using the prompt() method, ask the user for the number of each type of system to be built (Home PC, Gamer PC, Business PC, and Power User PC). Save each of the answers in a separate variable. You will need to use a separate prompt for each value.
When the user has entered all the data, use the confirm method to display the values entered, and ask the user if they are all OK. Use only a single confirm to display all the values! (You can assume the user will click OK. You do not need to write code to handle a case where the user clicks cancel instead of OK. That will be next week's assignment.)
Calculate the number of each component needed by taking the number of each type of system times the number of that component required for that type of system for all the types of systems. For example, an order for 1 Home PC, 0 Gamer PCs, 3 Business PCs, and 2 Power User PCs would need 6 CD/RW drives ( (1 * 1) + (0 * 0) + (3 * 1) + (2 * 1) ) == 6 . Do this for each of the components (Motherboard, RAM module, CD/RW drive, and DVD drive), and save each result in a separate variable.
Use the document.write method to display on the web page the results of the calculations. Your output should look like: For __ Home PCs, __ Gamer PCs, __ Business PCs, and __ Power User PCs, you will need to order:
__ Motherboard(s)
__ RAM Module(s)
__ CD/RW drive(s)
__ DVD drive(s)
Where the __ indicates where your computed values should go.
ASSIGNMENT #2:
For assignment, you will need the HTML/JavaScript program that you created last week for the JavaScript 1 project (PC Integrators). You will expand the program to include some conditional branching.
1. Open the text document of your solution to the PC Integrators problem.
2. You used a confirm method to display the number ordered of each system. The program assumed the user would press OK in the confirm box. Add an IF statement to the program that will display an alert box containing an error message, if the user presses CANCEL instead of OK. The message should advise the user to reload the page and re-enter the data.
3. Now add an ELSE/ IF structure, based on this data: If a customer orders more than 4 Home PC units, or more than 3 Gamer PC units, the customer qualifies for a 5% discount. If a customer orders 5 Business PC units, or any Power User units, that customer will qualify for a 10% discount. Otherwise the customer does not qualify for any discount. You want to have an ALERT box displayed if the customer qualifies for a discount ("Customer will receive a __ % discount."). If the customer does not qualify for a discount, use document.write to display the text "No discounts apply." You are required to use the ELSE/IF. You will also need to refer to your Boolean logical operators.
MY INCORRECT SOLUTION:
<html>
<head>
<title>JavaScript Assignment 1</title>
<body><h1 align="center"><font face="impact">Welcome to the configuration calculator!</h1>
<script language="Javascript">
document.write
var bc;
var gc;
var pu;
var bgh;
bc = prompt ("How many business computers would you like built?");
gc = prompt ("How many gaming computers would you like built?");
pu = prompt ("How many power user computers would you like built?");
bgh = prompt ("How many home computers would you like built?");
var confrim = confirm("You ordered " +bc+" business computers, " +gc+" gaming computers, " +pu+" power user computers, and " +bgh+" home computers");
var mb;
var mb = ((bc * 1) + (gc * 1) + (pu * 1) + (bgh * 1));
var ram = ((bc * 1) + (gc * 1) + (pu * 1) + (bgh * 1));
var dvd = ((bc * 1) + (gc * 1) + (pu * 1) + (bgh * 1));
var cdrw = ((bc * 1) + (gc * 1) + (pu * 1) + (bgh * 1));
document.write("You ordered " +bc+" Business Computers, " +gc+" Gaming Computers, " +pu+" Power User Computers, and " +bgh+" Home Computers. For this, you will need to order:<br>");
document.write( +mb+ " motherboards<br>");
document.write( +ram+ " ram modules<br>");
document.write( +cdrw+ " cd/rw drives<br>");
document.write( +dvd+ " dvd drives<br>");
if ((bgh>4)||(gc>3))
{
window.alert("You receive a 5% discount");
}
else if ((bc==5)||(pu>0));
{window.alert("You receive a 10% discount");
}
else
{window.alert("No discounts apply");
}
</script>
</html>