User:Davidboo25/common.js: Difference between revisions

From Melvor Idle
(testing js)
(No difference)

Revision as of 03:36, 2 April 2021

const combatLevel  = {
  displayValue: '0',
  firstOperand: null,
  waitingForSecondOperand: false,
  operator: null,
};



function handleOperator(nextOperator) {
  const { firstOperand, displayValue, operator } = combatLevel
  const inputValue = parseFloat(displayValue);
  
 
    const result = inputValue + 1

    combatLevel.displayValue = String(result);
    combatLevel.firstOperand = result;
  
  combatLevel.operator = nextOperator;
}



// TODO, do somthing in here so that every update display, we grab every text box's values
	// and then store it in a value.
  //  we can then take the values and add them up and do combat math on them.
function updateDisplay() {
  const display = document.querySelector('.output_screen');
  display.value = combatLevel.displayValue;
}

updateDisplay();

const keys = document.querySelector('.equals_button');
keys.addEventListener('click', (event) => {
  const { target } = event;
  if (!target.matches('button')) {
    return;
  }

  if (target.classList.contains('operator')) {
    handleOperator(target.value);
		updateDisplay();
    return;
  }


  inputDigit(target.value);
  updateDisplay();
});