# Untitled

unknown
plain_text
2 months ago
1.8 kB
2
Indexable
Never
```<!DOCTYPE html>
<html>
<title>Simple Calculator</title>
<script>
// Function to perform the addition operation
var num1 = parseFloat(document.getElementById("num1").value);
var num2 = parseFloat(document.getElementById("num2").value);
var result = num1 + num2;
document.getElementById("result").value = result;
}
// Function to perform the subtraction operation
function subtract() {
var num1 = parseFloat(document.getElementById("num1").value);
var num2 = parseFloat(document.getElementById("num2").value);
var result = num1 - num2;
document.getElementById("result").value = result;
}
DEPARTMENT OF ISE, RIT,
BANGALORE
23
// Function to perform the multiplication operation
function multiply() {
var num1 = parseFloat(document.getElementById("num1").value);
var num2 = parseFloat(document.getElementById("num2").value);
var result = num1 * num2;
document.getElementById("result").value = result;
}
// Function to perform the division operation
function divide() {
var num1 = parseFloat(document.getElementById("num1").value);
var num2 = parseFloat(document.getElementById("num2").value);
var result = num1 / num2;
if (isNaN(result)) {
document.getElementById("result").value = "Cannot divide by zero";
} else {
document.getElementById("result").value = result;
}
}
</script>
<body>
<h1>Simple Calculator</h1>
<label for="num1">Number 1:</label>
<input type="number" id="num1"><br>
<label for="num2">Number 2:</label>
<input type="number" id="num2"><br>