Program6
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Calculator</title>
<style>
body { font-family: Arial, sans-serif; display: flex; justify-content:
center; align-items: center; height: 100vh; margin: 0; background-color:
#f4f4f4; }
.calculator { background-color: #fff; padding: 20px; border-radius:
10px; box-shadow: 0 4px 8px rgba(0,0,0,0.2); }
input, button { padding: 10px; margin: 5px; border-radius: 5px;
border: 1px solid #ccc; font-size: 16px; }
button { background-color: #2ecc71; color: white; cursor: pointer; }
button:hover { background-color: #27ae60; }
input[type="number"] { width: 150px; text-align: center; }
.results { margin-top: 10px; }
</style>
</head>
<body>
<div class="calculator">
<h2>Calculator</h2>
<input type="number" id="num1" placeholder="Number 1">
<input type="number" id="num2" placeholder="Number 2">
<div>
<button onclick="calculate('sum')">Sum</button>
<button onclick="calculate('product')">Product</button>
<button onclick="calculate('difference')">Difference</button>
<button onclick="calculate('remainder')">Remainder</button>
<button onclick="calculate('quotient')">Quotient</button>
<button onclick="calculate('power')">Power</button>
<button onclick="calculate('sqrt')">Square Root</button>
<button onclick="calculate('square')">Square</button>
</div>
<div class="results">
<p id="result">Result: </p>
</div>
</div>
<script>
function calculate(operation) {
let num1 = parseFloat(document.getElementById('num1').value);
let num2 = parseFloat(document.getElementById('num2').value);
let result;
if (operation === 'sum') result = num1 + num2;
if (operation === 'product') result = num1 * num2;
if (operation === 'difference') result = num1 - num2;
if (operation === 'remainder') result = num1 % num2;
if (operation === 'quotient') result = num1 / num2;
if (operation === 'power') result = Math.pow(num1, num2);
if (operation === 'sqrt') result = Math.sqrt(num1);
if (operation === 'square') result = Math.pow(num1, 2);
document.getElementById('result').innerText = `Result: ${result}`;
}
</script>
</body>
</html>
Comments
Post a Comment