Почему не выдаёт результат??? Не могу никак понять, что не так…
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Калькулятор</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<script src="scrypt.js"></script>
<div class="calc">
<div class="area">
<p class="input">Введите первое число: <input class="poleVvoda" type="text" id="firstNum"></p>
<select class="operation" name="operation" required="required" id="operation">
<option value="">Выберите действие:</option>
<option value="1">+</option>
<option value="2">-</option>
<option value="3">*</option>
<option value="4">/</option>
</select>
<p class="input">Введите второе число: <input class="poleVvoda" type="text" id="secondNum"></p>
<button class="btn" id="result">Результат</button>
<p id="out"></p>
</div>
</div>
</body>
</html>
JS:
document.getElementById('result').onclick = function () {
let firstNum = document.getElementById('firstNum').value;
firstNum = parseInt(firstNum);
let secondNum = document.getElementById('secondNum').value;
secondNum = parseInt(secondNum);
let result;
let operation = document.getElementById('operation')
let x = operation.value;
let out = document.getElementById('out');
if (x = 1) {
result = firstNum + secondNum;
out.innerHTML = result;
console.log(result);
}
else if (x = 2) {
result = firstNum - secondNum;
out.innerHTML = result;
console.log(result);
}
else if (x = 3) {
result = firstNum * secondNum;
out.innerHTML = result;
console.log(result);
}
else if (x = 4) {
result = firstNum / secondNum;
out.innerHTML = result;
console.log(result);
}
else {
out.innerHTML = "Выберите операцию";
}
};