0% found this document useful (0 votes)
2 views2 pages

Notepad

This document is an HTML code for a simple calculator web application. It includes input fields for two numbers and buttons for basic arithmetic operations: addition, subtraction, multiplication, and division. The calculator displays the result or an error message based on user input and operations performed.

Uploaded by

acharyakalyan657
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Notepad

This document is an HTML code for a simple calculator web application. It includes input fields for two numbers and buttons for basic arithmetic operations: addition, subtraction, multiplication, and division. The calculator displays the result or an error message based on user input and operations performed.

Uploaded by

acharyakalyan657
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

<

<!DOCTYPE html>
<html>
<head>
<title>Simple Calculator</title>
<style>
body {
font-family: Arial;
text-align: center;
margin-top: 50px;
}
input {
padding: 10px;
margin: 5px;
width: 100px;
}
button {
padding: 10px;
margin: 5px;
}
</style>
</head>
<body>

<h2>Simple Calculator</h2>

<input type="number" id="num1" placeholder="First number">


<input type="number" id="num2" placeholder="Second number">
<br>

<button onclick="calculate('+')">Add</button>
<button onclick="calculate('-')">Subtract</button>
<button onclick="calculate('*')">Multiply</button>
<button onclick="calculate('/')">Divide</button>

<h3 id="result">Result: </h3>

<script>
function calculate(operator) {
const n1 = parseFloat([Link]('num1').value);
const n2 = parseFloat([Link]('num2').value);
let result;
if (isNaN(n1) || isNaN(n2)) {
result = "Please enter valid numbers.";
} else {
switch (operator) {
case '+': result = n1 + n2; break;
case '-': result = n1 - n2; break;
case '*': result = n1 * n2; break;
case '/':
result = n2 === 0 ? "Error: Division by zero" : n1 / n2;
break;
}
}

[Link]('result').textContent = "Result: " + res


ult;
}
</script>

</body>
</html>

You might also like