Q:

Why my javascript program is not converting it to integer rather than string?

i have created a simple program in which it needs to add 1 and 3 and show 4 but it shows me 13 here is my program:
<html>
    <head>
        <style>
        </style>
        <script type="text/javascript">
        function calculate(){

            a = document.getElementById('num1').value;
            b = document.getElementById('num2').value;
            document.getElementById('result').innerHTML = a + b;
        }
        </script>
    </head>
    <body>
        <input id='num1' value="1"/>
        <input id='num2' value='3'/>
        <p id='result'></p>
        <button onclick="calculate()">Calculate</button>
    </body>
</html>

What do i do now?

A:

That's because value attribute returns a String. You need to convert it to a Number.
There's a shortcut though, by using + unary operator. You can also wrap the string in Number like Number(a) + Number(b).
a = +document.getElementById('num1').value;
b = +document.getElementById('num2').value;

