title: Add two numbers in JavaScript function
body: <p>I am a beginner in JavaScript. Our teacher asked us to write a program to add two numbers using function add(). The question is shown as follows.</p>
  
  <p>However, when I use my code to add the two numbers. The result is not a number.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
      &lt;head&gt; &lt;title&gt; Third example &lt;/title&gt;
       &lt;script type="text/javascript"&gt;
       function sum (x,y)
       { num1=parseInt(x);
       num2=parseInt(y);
       return (num1+num2);}
       var input1 = window.prompt("Enter a number: ", 0);
       var input2 = window.prompt("Enter another number: ", 0);
       var input3 = window.prompt("Enter another number: ", 0);
       var value1 = parseFloat(input1 + input2);
       var value3 = parseFloat(input3);
       var sum = sum(value1 + value3);
       document.writeln("&lt;h1&gt; First number: " + value1 + "&lt;/h1&gt;");
       document.writeln("&lt;h1&gt; Second number: " + value3 + "&lt;/h1&gt;");
       document.writeln("&lt;h1&gt; Sum: " + sum + "&lt;/h1&gt;");
       &lt;/script&gt; 
      &lt;head&gt;
      &lt;body&gt;&lt;/body&gt; &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Why the sum is not a number?</p>