I am trying to build a basic calculator. I seem to have done everything right. I am trying to get the buttons to show up on the screen as they are being pressed but I keep on getting an undefined value.
When I console.log the numbers. I get an array value. I have converted them to arrays and I see the correct innerText value but I still can't get them to display on my calculator display.
'use strict'
const input = document.querySelector('.calculator-display');
const number = document.querySelectorAll('.number-buttons');
const numbers = Array.from(number)
numbers.forEach(button => {
button.addEventListener('click', function() {
input.value = number.innerText;
});
});
.calculator-display {
height: 200px;
width: 85%;
background-color: white;
font-size: 7rem;
}
.operator-buttons {
width: 20%;
height: 50px;
font-size: 2.5rem;
margin: 0;
padding: 10px;
}
.number-buttons {
width: 20%;
height: 50px;
font-size: 2.5rem;
margin: 0;
padding: 10px;
}
<input type="text" class="calculator-display" />
<div class="buttons">
<button class="operator-buttons">*</button>
<button class="operator-buttons">/</button>
<button class="operator-buttons">-</button>
<button class="operator-buttons">+</button>
<button class="number-buttons">.</button>
<button class="number-buttons">9</button>
<button class="number-buttons">8</button>
<button class="number-buttons">7</button>
<button class="number-buttons">6</button>
<button class="number-buttons">5</button>
<button class="number-buttons">4</button>
<button class="number-buttons">3</button>
<button class="number-buttons">2</button>
<button class="number-buttons">1</button>
<button class="number-buttons">0</button>
<button class="number-buttons">=</button>
<button class="number-buttons">DELETE</button>
</div>