This is a discussion on "while loops?" within the JavaScript Forum section. This forum, and the thread "while loops? are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
while loops?
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
while loops?
Dear all programming experts,
Can somebody please help me with my jazascript program. Here's my script, but I'd like to get my program to give me the total motherboards(variable M), total RAM Modules(variable M) etc. that all customers would need for the amount of computers that they entered in the prompt message. For example, if there are three customers using this program, and they all enter the amount of each type of computer that they want, how can I get the total of all motherboards, RAM's etc. that all the customers ordered, corresponding to the computers they want? Another part that I would like to know how to do, is how to create a while loop around the part of the program that prompts the user for the number of systems(Home PC's, Gamers etc.)of each type. The loop should be inside the for loop already in the program. I want to create a variable to use as a sentinel for the loop. The sentinel should take its value from the return value of the "confirm" method that asks if the values are OK. When the user clicks OK, the "while" loop should terminate. But if the user clicks cancel, the loop should re-prompt for all four values. (Right now I have an "if" structure that handles the possibility of the user clicking cancel. But I believe the "while" loop should replace this "if" structure, and if the user clicks cancel, the loop will just re-prompt for all four values. As in Part 1, when the "for" loop is completed(data has been entered for all customers), the program should print out the accumulated totals for each component.("You need a total of _Motherboards, _RAM Modules etc...") If somebody can only help with one part of this program that is great, and thank you very much in advance for your time and "input." <HTML> <Head> <TITLE>JAVAScript</TITLE> </Head> <BODY> <Script Language:"javascript"> var total = 0; var customertotal= window.prompt("How many customers will use this PC Integrators program?>>"); for(i=0;i<Number(customertotal);i++){ var name = prompt("name of customer "+i+""); var x= window.prompt("Number of Home PC's for Customer "+i+"?>>"); var y= window.prompt("Number of Gamer PC's for Customer "+i+"?>>"); var z= window.prompt("Number of Business PC's for Customer "+i+"?>>"); var pu= window.prompt("Number of Power user PC's for Customer "+i+"?>>"); var M = ((x*1)+(y*1)+(z*1)+(pu*1)) var R = ((x*1)+(y*2)+(z*4)+(pu*4)) var C = ((x*1)+(y*0)+(z*1)+(pu*1)) var D = ((x*0)+(y*1)+(z*0)+(pu*1)) var check=window.confirm("For customer "+i+" who wants, "+x+" Home PC's, "+y+" Gamer PC's, "+z+" Business PC's, and "+pu+" Power User PC's; will need to order: "+M+" motherboards, "+R+" RW drives, "+C+" CD Drives, and "+D+" DVD Drives"); total += Number(M)+Number(R)+Number(C)+Number(D); if (!check) { alert("Error: Please reload the page and re-enter the data!"); } else { var discount =0; if ( (x >4) || (y>3)) { discount = discount + 5; } if ( (z==5) || (pu>0)) { discount = discount + 10; } if(discount!=0){ alert("customer "+i+" will receive a discount of "+ discount +"% for "+x+" Home PC's, "+y+" Gamer PC's, "+z+" Business PC's, and "+pu+" Power User PC's if he orders: "+M+" Motherboards, "+R+" RW-drives, "+C+" CD drives, and "+D+" DVD drives"); } else { document.write(" customer "+i+" you do not qualify for a discount</p>"); } } } alert(total); </script> name : Michael Gabovich </p> </body> </html> |
|
|
|
#2
|
|||
|
|||
|
mikegu, please do not post the same thread in 3 different places, It makes following the forum very difficult. I have deleted the other two threads that were identical to this one.
|
![]() |
| Tags |
| while, loops |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Logic Problem involving loops and arrays | tox0tes | Other Programming Languages | 5 | Oct 28th, 2007 03:11 |
| Free Flash music and ambient loops | equinoxsounds | Flash & Multimedia Forum | 3 | Oct 12th, 2007 09:57 |
| Limiting While Loops | Weird1993 | Databases | 5 | Jul 12th, 2007 04:33 |