Test
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
<style>
#calculator {
width: 200px;
padding: 10px;
border: 1px solid #ccc;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
}
input[type="text"] {
width: 100%;
margin-bottom: 10px;
padding: 5px;
}
input[type="button"] {
width: 48%;
padding: 5px;
margin: 1%;
}
</style>
<script>
function calculate() {
var num1 = parseFloat(document.getElementById('num1').value);
var num2 = parseFloat(document.getElementById('num2').value);
var operator = document.getElementById('operator').value;
var result;
if (operator === '+') {
result = num1 + num2;
} else if (operator === '-') {
result = num1 - num2;
} else if (operator === '*') {
result = num1 * num2;
} else if (operator === '/') {
result = num1 / num2;
}
document.getElementById('result').value = result;
}
</script>
</head>
<body>
<div id="calculator">
<input type="text" id="num1" placeholder="Enter number 1">
<select id="operator">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="num2" placeholder="Enter number 2">
<input type="button" value="Calculate" onclick="calculate()">
<input type="text" id="result" placeholder="Result" readonly>
</div>
</body>
</html>
Comments
Post a Comment