|
|
(6 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| const combatLevel = {
| | $(function () { |
| displayValue: '0',
| | var myElement = document.getElementById('calculatorTest'); |
| firstOperand: null,
| | myElement.innerHTML = '<input type=\"number\" min=\"0\" oninput=\"validity.valid||(value=\'\');\" class=\"number_input\" id=Ranged value=\"\" enabled />'; |
| 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();
| |
| });
| |