<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<title>Калькулятор</title>
</head>
<body>
<h3>Калькулятор</h3>
<input id="num1" type="number" placeholder="Первое число">
<br><br>
<div>
<button onclick="op='+'">+</button>
<button onclick="op='-'">-</button>
<button onclick="op='*'">×</button>
<button onclick="op='/'">÷</button>
</div>
<br><br>
<input id="num2" type="number" placeholder="Второе число">
<br><br>
<button onclick="
const a = parseFloat(document.getElementById('num1').value);
const b = parseFloat(document.getElementById('num2').value);
const resEl = document.getElementById('result');
if (isNaN(a) || isNaN(b)) {
resEl.textContent = 'Пожалуйста, введите оба числа.';
return;
}
if (op === '/' && b === 0) {
resEl.textContent = 'Деление на ноль невозможно.';
return;
}
let res;
if (op === '+') res = a + b;
else if (op === '-') res = a - b;
else if (op === '*') res = a * b;
else if (op === '/') res = a / b;
resEl.textContent = 'Результат: ' + res;
">Посчитать</button>
<p id="result"></p>
<script>
var op = '+';
</script>
</body>
</html>