Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're re-iterating the loop if the user hits <code>cancel</code>. Change <code>while(a==false)</code> to <code>while(a==true)</code> or simply <code>while(a)</code></p> <p>Also put the line</p> <pre><code>a = confirm("Do you want to place another order?"); </code></pre> <p>as the last line <strong>in</strong> your loop, instead of the line after.</p> <p>You can set a flag var that lets you know if the item was found or not and check it at the end of your loop to avoid displaying data for non-existing items:</p> <pre><code>&lt;script type="text/javascript"&gt; /*Daniel Weiner, Fengpeng Yuan, Javascript 2, Nov 4,2011*/ var username; var bprice= 8; var chprice= 9; var sprice= 2; var fprice= 4; var price= 0; var a; var b; var product= "hamburger, cheeseburger, soda, fries"; var quantity =0; var total; var cost = 0; var discount= 0; var flag; do{ flag = true; //assume found unless otherwise username =prompt("Welcome to Big Ben's Burgers. Please enter your name.", ""); alert("Hello " + username+". Please look through our available products and services before placing your order.",""); product=prompt("What do you want?",""); quantity =1*prompt("How many of " +product+ " would you like?"); if (product == "hamburger") { price = bprice; discount = .1; } else if (product == "cheeseburger") { price = chprice; discount = .05; } else if (product == "soda") { price = sprice; discount = .07; } else if (product == "fries") { price = fprice; discount = .15; } else{ alert("Sorry, " +username+ " Your item not found."); flag = false; } if(flag){ cost=price*quantity discount=price*discount*quantity total=cost-discount document.write("The cost of buying " +quantity+ " of " +product+ " is $" +cost+ ".&lt;br/&gt;"); document.write("This discount for this purchase is $" +discount+ ".&lt;br/&gt;"); } a = confirm("Do you want to place another order?"); }while(a); alert('goodbye'); &lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload