← Back to Forum

addition in js

Posted on December 4, 2024, 1:52 pm


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Addition in with user input</title>
</head>
<body>
<input type="number" placeholder="Enter Num 1" id="num1">
<input type="number" placeholder="Enter Num 2" id="num2">
<button onclick="sum()">Add</button>
<hr>
<h1 id="res"></h1>
<script>
function sum() {
var x,y,z;
x = parseInt(document.getElementById("num1").value);
y = parseInt(document.getElementById("num2").value);
z=x+y;
document.getElementById("res").innerHTML = z;
}
</script>
</body>
</html>


Add a Reply


Replies (0)

No replies yet. Be the first to reply!