Assuming that firstNum
and secondNum
are input fields you would need to get the value of these inputs. Input values are string so you also would need to cast the values to numbers.
var result = document.getElementById('result');
var firstNum = document.getElementById('number1');
var secondNum = document.getElementById('number2');
firstNum.addEventListener('keyup', sum);
secondNum.addEventListener('keyup', sum);
function sum(e){
var mySum = Number(firstNum.value) + Number(secondNum.value);
console.log(mySum);
}
CLICK HERE to find out more related problems solutions.