Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I haven't tested but I suspect that your code works by default almost but only problem is that you are not declaring your <code>score</code> variable in the global scope, that way the same variable can be accessed by other functions without further passing.</p> <p>Adding <code>var score = 0;</code> to top of page should make it work and later use it without <code>var</code> like <code>score++;</code> to increase by one, <code>score = 0;</code> to reset it and so on.. Rest of the code I leave you as a puzzle, since its school work anyway - just wanted to en-light you about usage of global variables. :) However try to avoid creating lots of global variables because it is also known as bad practice, although its sometimes hard to live without them. Read more from <a href="https://stackoverflow.com/questions/10525582/why-are-global-variables-considered-bad-practice-javascript">global variables, bad practice?</a></p> <p>Few debugging tips for your code:</p> <pre><code>var scoreElement=document.getElementById("score"); </code></pre> <p>This line is executed before DOM is loaded, so it might be null.. Try to change lines:</p> <pre><code>alert("Addition: Correct"); scoreElement.value=score; </code></pre> <p>To</p> <pre><code>document.getElementById("score").value=score; </code></pre> <p>Also move all of your javascript to bottom of page (for example under: <code>&lt;/body&gt;</code> tag) - thats the right way to do it. Also why you are loading jquery.js when you are not really using it? For example you could add all your javascript code to inside document ready. Like this:</p> <pre><code>$(function() { // your javascript code }); </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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