js-calculator/main.js
2022-05-03 13:49:39 +03:00

36 lines
No EOL
814 B
JavaScript

const dis_big = document.getElementById("dis_big");
const dis_sml = document.getElementById("dis_sml");
const calc = new Calculator();
const buttons = document.querySelector('.buttons');
buttons.addEventListener('click', e => {
const value = e.target.value;
PressButton(value);
})
function PressButton(button) {
calc.pressbutton(button);
tmp = '';
switch (calc.operator) {
case 'ADD':
tmp = ' +';
break;
case 'SUB':
tmp = ' -';
break;
case 'MUL':
tmp = ' *';
break;
case 'DIV':
tmp = ' /';
break;
default:
console.log('Invalid operator');
break;
}
dis_big.innerText = calc.curr;
dis_sml.innerText = calc.prew + tmp;
}