if (target.matches('button')) {
if (action === 'number') {
if(firstNum === undefined){
display.textContent = buttonContent
firstNum = buttonContent
}else{
display.textContent = display.textContent + buttonContent
}
lastNum = display.textContent
copyCount = 0
}
if(action === 'operator'){
firstNum = undefined
dotNum = undefined
if(copyCount === 0){
if(count === 0){
previousNum = display.textContent
count = count + 1
operatorForAdvanced = buttonContent
}else if(calculateButton === undefined){
display.textContent = calculate(previousNum, operatorForAdvanced, lastNum)
previousNum = display.textContent
operatorForAdvanced = buttonContent
}
copyCount = 1
}
if(lastNum === previousNum){
operatorForAdvanced = buttonContent
}
}
if (action === 'decimal') {
if(dotNum === undefined){
if(firstNum === undefined){
display.textContent = '0' + buttonContent
}else{
display.textContent = display.textContent + buttonContent
}
firstNum = buttonContent
dotNum = buttonContent
}
}
if (action === 'clear') {
display.textContent = '0'
firstNum = undefined
operatorForAdvanced = undefined
previousNum = undefined
lastNum = undefined
dotNum = undefined
count = 0
copyCount = 0
calculateButton = undefined
}
if (action === 'calculate') {
calculateButton = buttonContent
if(operatorForAdvanced !== undefined){
dotNum = undefined
if(previousNum !== undefined){
display.textContent = calculate(previousNum, operatorForAdvanced, lastNum)
previousNum = undefined
}else{
display.textContent = calculate(display.textContent, operatorForAdvanced, lastNum)
}
}
}
}