Learn the code that adds 2 numbers in a calculator. Program running behind a calculator.
Languages used in this video – HTML, JavaScript.
<html>
<head>
<title>Calculator</title>
</head>
<body>
<input type="number" id="val1">
<input type="number" id="val2">
<button onClick="cal()">Add</button>
<div id="result"></div>
<script>
function cal(){
var v1 = document.getElementById("val1").value;
var v2 = document.getElementById("val2").value;
document.getElementById("result").innerHTML = Number(v1) - Number(v2);
}
</script>
</body>
</html>