So, I'm trying to build a calculator and the first thing I want to do is to display all the buttons in my output. I have created a function called displayButtons and inside, I got the first 2 buttons by id however, when I try to display them, only the number 2 displays. One way to fix this is to create a function for each numbers and then it'll work but that's not what I want. I've also tried nesting the functions for each number within a function, but I wasn't able to call it properly onclick. Any ideas? Thanks in advance!
HTML code:
<div id="output"></div>
<div class="numbers">
<button value="1" id="one" onclick="displayButtons()">1</button>
<button value="2" id="two" onclick="displayButtons()">2</button>
JS code:
function displayButtons() {
var one = document.getElementById("one").value;
document.getElementById("output").innerHTML = one;
var two = document.getElementById("two").value;
document.getElementById("output").innerHTML = two
}