Вот весь код "Калькулятора"
let a = '';
let b = '';
let sign = '';
let finish = false;
const digit = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.'];
const action = ['+', '-', 'X', '/'];
const out = document.querySelector('.calc-text p');
function clearAll() {
a = '';
b = '';
sign = '';
finish = false;
out.textContent = 0;
}
document.querySelector('.ac').onclick = clearAll;
document.querySelector('.buttons').onclick = (event) => {
if (!event.target.classList.contains('btn')) return;
if (event.target.classList.contains('ac')) return;
out.textContent = '';
const key = event.target.textContent;
// если нажата кнопка 0-9 или .
if (digit.includes(key)) {
if (b === '' && sign === '') {
a += key;
out.textContent = a;
}
else if (a !== '' && b !== '' && finish){
finish = false;
b += key;
out.textContent = b;
}
else{
b += key;
out.textContent = b;
}
console.log(a, b, sign);
return;
}
if (action.includes(key)) {
sign = key;
console.log(a, b, sign);
out.textContent = sign;
}
if (key === '='){
if (b === '') b = a;
switch (sign) {
case '+':
a = (+a) + (+b);
break;
case '-':
a -= b;
break;
case '/':
a /= b;
Math.floor(a*100)/100;
break;
case 'X':
a *= b;
break;
}
finish = true;
b = '';
out.textContent = a;
console.log(a, b, sign);
}
}
не работает эта часть кода.
case '/':
a /= b;
Math.floor(a*100)/100;
break;