Note that there are some explanatory texts on larger screens.

plurals
  1. POHow come this line of code returns me an "undefined" then followed by a value
    text
    copied!<p>How come method equal always returns with an "undefined" followed by a number? and when I try to parse it. it returns me a NaN.</p> <pre><code>&lt;!DOCTYPE&gt; &lt;html&gt; &lt;head&gt; &lt;script&gt; var fnum; var secondNum; var operation; function msg(val) { document.getElementById("fnumtext").value += val; fnum += val; } function showOperation(oper) { document.getElementById("fnumtext").value = ""; document.getElementById("operation").value = oper; operation = oper; } function equal() { secondNum = document.getElementById("fnumtext").value; alert(fnum); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input id = "fnumtext"type="text" name="firstnum" /&gt;&lt;br /&gt; &lt;input id = "operation" type="text" name="secondnum" /&gt;&lt;br /&gt; &lt;input type="button" value="1" onclick="msg('1')" /&gt; &lt;input type="button" value="2" onclick="msg('2')" /&gt; &lt;input type="button" value="3" onclick="msg('3')" /&gt;&lt;/br&gt; &lt;input type="button" value="4" onclick="msg('4')" /&gt; &lt;input type="button" value="5" onclick="msg('5')" /&gt; &lt;input type="button" value="6" onclick="msg('6')" /&gt;&lt;br/&gt; &lt;input type="button" value="7" onclick="msg('7')" /&gt; &lt;input type="button" value="8" onclick="msg('8')" /&gt; &lt;input type="button" value="9" onclick="msg('9')" /&gt;&lt;/br&gt; &lt;input type="button" value="0" onclick="msg('0')" /&gt;&lt;/br&gt; &lt;input type="button" value="+" onclick="showOperation('+')" /&gt; &lt;input type="button" value="*" onclick="showOperation('*')" /&gt; &lt;input type="button" value="/" onclick="showOperation('/')" /&gt; &lt;input type="button" value="-" onclick="showOperation('-')" /&gt; &lt;input type="button" value="=" onclick="equal()" /&gt; &lt;/body&gt; &lt;/html&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