let operand;let operation;let displayString = '0';function updateDisplay() {document.getElementById('display').value = displayString;}function addDigit(digit) {if (displayString === '0') {displayString = digit;} else {displayString += digit;}updateDisplay();}function doAddition() {operand = parseInt(displayString);displayString = '0';operation = '+';}function doSubtraction() {operand = parseInt(displayString);displayString = '0';operation = '-';}function doMultiplication() {operand = parseInt(displayString);displayString = '0';operation = '*';}function doDivision() {operand = parseInt(displayString);displayString = '0';operation = '/';}function doClear() {operand = undefined;operation = undefined;displayString = '0';updateDisplay();}function doEquals() {if (operand === undefined || operation === undefined) {return;}let secondOperand = parseInt(displayString);if (operation === '+') {displayString = operand + secondOperand;} else if (operation === '-') {displayString = operand - secondOperand;} else if (operation === '*') {displayString = operand * secondOperand;} else if (operation === '/') {displayString = operand / secondOperand;}operand = undefined;operation = undefined;updateDisplay();displayString = '0';}function keyPress(event) {if (event.key >= '0' && event.key <= '9') {addDigit(event.key);} else if (event.key === '+') {doAddition();} else if (event.key === '-') {doSubtraction();} else if (event.key === '*') {doMultiplication();} else if (event.key === '/') {doDivision();} else if (event.key === 'Enter') {doEquals();} else if (event.key === 'c') {doClear();}}document.addEventListener('keydown', keyPress);