Question:

Hi all i study java script and i want to know why this code didn't want to work what wrong with it?

by  |  earlier

0 LIKES UnLike

<html>

<body>

<script>

var totalInventory=700

var numberPurchased=200

var numberSales=0

while (totalInventory > numberPurchased) {

totalInventory = totalInventory - numberPurchased

numberSales++

}

document.write(“Our stock supply will support “ +numberSales

+ “ of these bulk sales”)

</script>

</body>

</html>

 Tags:

   Report

2 ANSWERS


  1. Well, you&#039;re certainly getting the hang of some of this but it looks like you need to go back over the basics because the three errors I can see are all basic issues.

    You forget to declare what type of script:

    &lt;script type=&quot;text/javascript&quot;&gt;

    You are forgetting the semi-colons ;;; at the end of each statement:

    document.write(&quot;Hello World!&quot;);

    You have smart quotes (curly ones) instead of straight quotes &quot;&quot;, suggesting you might be using a word processor like Microsoft Word instead of a text editor like NotePad.  Admittedly, you can sometimes get away with smart quotes but HTML doesn&#039;t really handle it well.  Also, it may be pasting it into Yahoo that caused your smart quotes.

    For more help with your learning, try W3C Schools - W3C are the official standard setters of the internet.  Here&#039;s the javascript tutorial:

    http://w3schools.com/js/default.asp

    All the best!

    EDIT:

    Your smart quotes have gone straight on me - I think it must be Yahoo.  :-)


  2. You have not told the browser what kind of script it is looking at, you should terminate each line of code with a semi-colon also. Also, I noticed you are quoting inside the document.write using curly quotes and must be using &amp; ldquo; and &amp; rdquo; (without the spaces after the &amp;). That will not work on it&#039;s own in a script you should use standard quotes, not html entity&#039;s or codes. If you want the quotes to show in what is written, wrap the html entity&#039;s or codes in standard quotes outside of them - for example- document.write(&quot;&amp; ldquo; -without the space after the &amp;

    &lt;html&gt;

    &lt;head&gt;

    &lt;title&gt;&lt;/title&gt;

    &lt;/head&gt;

    &lt;body&gt;

    &lt;script type=&quot;text/javascript&quot;&gt;

    var totalInventory=700;

    var numberPurchased=200;

    var numberSales=0;

    while (totalInventory &gt; numberPurchased) {

    totalInventory = totalInventory - numberPurchased;

    numberSales++;

    }

    document.write(&quot;Our stock supply will support &quot; +numberSales

    + &quot; of these bulk sales&quot;);

    &lt;/script&gt;

    &lt;/body&gt;

    &lt;/html&gt;

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.