User:Davidboo25/common.js

< User:Davidboo25
Revision as of 03:36, 2 April 2021 by Davidboo25 (talk | contribs) (testing js)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
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();
});