// если нажата клавиша 0-9 или . if (digit.includes(key)) { if (b ==='' && sign === ''){ a += key; console.log(a, b, sign); out.textContent = a; } else if (a!=='' && b!=='' && finish) { b = key; finish = false; out.textContent = b; } else { b += key; out.textContent = b; } console.table(a, b, sign); return; }
// если нажата клавиша + - X / if (action.includes(key)) { sign = key; out.textContent = sign; console.table(sign); return; }
// нажата = if (key === '=') { if (b ==='') b = a; switch (sign) { case "+": a = (+a) + (+b); break; case "-": a = a - b; break; case "X": a = a * b; break; case "/": if (b === '0') { out.textContent = 'Ошибка'; a = ''; b = ''; sign = ''; return; } a = a / b; break; } finish = true; out.textContent = a; console.table(a, b, sign); }