Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason is this line:</p> <pre><code>goFish(smallnets); </code></pre> <p>You haven't declared a <code>smallnets</code> variable anywhere, but you have an element in your markup with the <code>id</code> <code>"smallnets"</code> which is a <code>span</code>. Most browsers create global variables for elements with <code>id</code> values, where the name of the variable is the <code>id</code> and the value is the DOM element.</p> <p>Then in <code>goFish</code>, this line:</p> <pre><code>anchovies = anchovies + num; </code></pre> <p>is (on the first pass):</p> <pre><code>anchovies = 0 + a_span_element; </code></pre> <p>Since the <code>span</code> can't be reasonably converted to a number, it's converted to a string, which is <code>"[object HTMLSpanElement]"</code>. Then the <code>0</code> is converted to a string and you have <code>"0[object HTMLSpanElement]"</code>.</p> <p>And then the next time the interval fires, you add another copy of <code>"[object HTMLSpanElement]"</code> to it, etc., etc.</p> <p>If your goal is to use the <em>text</em> of the <code>span</code>, you want:</p> <pre><code>goFish(smallnets.innerHTML); </code></pre> <p>or better</p> <pre><code>goFish(parseInt(smallnets.innerHTML, 10)); </code></pre> <p>or even better, don't rely on the global created via the <code>id</code>:</p> <pre><code>goFish(parseInt(document.getElementById("smallnets").innerHTML, 10)); </code></pre> <p>You'll also want to put <code>0</code> or something in the span, e.g.:</p> <pre><code>&lt;span id="smallnets"&gt;0&lt;/span&gt; </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. 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