I'm making a calculator but have a problem storing the value after clicking on the plus symbol and then choose another number to click on the equal symbol and get the result. Help me please! XP
let firstValue;
let secondValue;
document.querySelector('#addOperator').addEventListener('click', function() {
if(document.querySelector('#addOperator')) {
firstValue = document.querySelector('#output').textContent;
// document.querySelector('#output').textContent = '';
// console.log(firstValue);
console.log(document.querySelector('#output').textContent);
};
});
document.getElementById('equals').addEventListener('click', function() {
if(document.querySelector('#output').textContent === firstValue) {
secondValue = document.querySelector('#output').textContent;
// console.log(secondValue);
// document.querySelector('#output').textContent = add(firstValue, secondValue);
console.log(document.querySelector('#output').textContent = add(firstValue, secondValue));
};
});
My html document is this------------------------------------------------------------->
<!-- Calculator display -->
<div id="output">
<!-- <div id="previous-operand"></div>
<div id="current-operand"></div> -->
</div>
<button class="span-two" id="ac-color">AC</button>
<button id="clear-entry">CE</button>
<button id="divideOperator">÷</button>
<button class="number">7</button>
<button class="number">8</button>
<button class="number">9</button>
<button id="multiplyOperator">*</button>
<button class="number">4</button>
<button class="number">5</button>
<button class="number">6</button>
<button id="addOperator">+</button>
<button class="number">1</button>
<button class="number">2</button>
<button class="number">3</button>
<button id="subtractOperator">-</button>
<button class="number">0</button>
<button class="number">.</button>
<button class="span-two" id="equals">=</button>