text: const $numbersWrapper = document.querySelector('section[class="numbers"]')
  const $operatorsWrapper = document.querySelector('section[class="operators"]')
  const $result = document.querySelector('.result')
  const $clearButton = document.querySelector('.ac')
  const $answerButton = document.querySelector('.answer')
  
  let result = ''
  let leftOperand = ''
  let operator = ''
  let rightOperand = ''
  
  // 할당된 변수 초기화
  const reset = () => {
    leftOperand = ''
    operator = ''
    rightOperand = ''
  }
  
  // 초기화 작업
  const clearFormula = () => {
    $result.innerText = ''
    reset()
  }
  
  // 숫자 눌렀을 때
  $numbersWrapper.addEventListener('click', (event) => {
    if (event.target.className !== 'number') return
  
    if (operator === '') { // 연산자 누르기 전
      leftOperand = event.target.innerText
    } else { // 연산자 누른 후
      rightOperand = event.target.innerText
    }
  
    $result.innerText = event.target.innerText
  })
  
  // 연산자 눌렀을 때
  $operatorsWrapper.addEventListener('click', (event) => {
    if (event.target.className !== 'operator') return
  
    if (result !== '' && leftOperand === '') {
      leftOperand = result
    }
  
    operator = event.target.innerText
  })
  
  // 초기화 버튼 눌렀을 때
  $clearButton.addEventListener('click', () => {
    clearFormula()
  })
  
  // 결과 버튼 눌렀을 때
  $answerButton.addEventListener('click', () => {
    switch (operator) {
      case '+':
        result = Number(leftOperand) + Number(rightOperand)
        break
      case '-':
        result = Number(leftOperand) - Number(rightOperand)
        break
      case '×':
        result = Number(leftOperand) * Number(rightOperand)
        break
      case '÷':
        result = Number(leftOperand) / Number(rightOperand)
        if (isFinite(result)) {
          result = Math.floor(result)
        }
        break
      default:
        break
    }
  
    $result.innerText = result
    reset()
  })