Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should clean up your code a bit:</p> <ul> <li>Indent everything to make it more readable</li> <li>Remove the <code>&lt;center&gt;</code> and <code>bgcolor="white"</code> parts since they do not add anything - your <code>&lt;center&gt;</code> element is empty, and a page is white by default and <code>bgcolor</code> is deprecated anyway</li> <li>All your JavaScript code should be just in one block, no need for three of them. Also you should put all JavaScript into the head instead of mixing part of it into the body</li> <li>Your code should not work because of your <code>;</code> after the <code>}</code> of <code>if</code>, but since you said it worked partially this probably is not the problem. Be sure not to put <code>;</code>s after <code>if</code> clauses, though.</li> </ul> <p>A working version: <a href="http://jsfiddle.net/pimvdb/2dqSr/" rel="nofollow">http://jsfiddle.net/pimvdb/2dqSr/</a>.</p> <pre><code>var result = 0; // result is 0 at first var meal = +prompt("Number of Items: "); // convert into a number with + var tip = 1.07; if (meal &gt; 0) { var index = 0; while (index &lt; meal) { var price = +prompt("price of the item"); result = result + price; // add price to result index++; // increment index, so that while loop will stop after 'meal' times. // If you set it to 'meal' directly, then 'index' will be equal to // 'meal' after the first iteration, and the while loop will only // run once (after the first iteration 'index &lt; meal' is false). } alert(result * tip); // alert total price * tip } else if (meal == 0) { alert("Number is 0"); } else if (meal &lt; 0) { alert("You entered is negative"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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