Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
How can I infinitely add numbers from my createElement?

I am making a calculator, and creating a new element (the number) every time I press an operator button. I'm wondering how I can get it to where I can infinitely add numbers (1+1+1+1 etc) every time i create the element. I think I'll need to store the current total number somehow, but I can't figure out how to do it. If you need any clarification let me know! Thanks HTML

    <button class="numbers">0</button>
    <button class="numbers">1</button>
    <button class="numbers">2</button>
    <button class="numbers">3</button>
    <button class="numbers">4</button>
    <button class="numbers">5</button>
    <button class="numbers">6</button>
    <button class="numbers">7</button>
    <button class="numbers">8</button>
    <button class="numbers">9</button>
    <button id="addition" class="button-operator">+</button>
    <button id="equals" class="button-operator">=</button>
   <div class="result-container">
    <h1 id="value"></h1>
    <h1 id="equal"></h1>
    </div>

JS

const numbersArray = Array.from(document.querySelectorAll('.numbers'));
const addition = document.getElementById('addition');
const equal = document.getElementById('equal');
const equalSign = document.getElementById('equals');
let newValue = document.createElement('h1');

numbersArray.forEach(element => {
    element.addEventListener('click', (e) => {
        newValue.innerText = e.target.innerText;
        function resultHandler() {
            value.innerText = ''
        }

        addition.addEventListener('click', (e) => {
            resultHandler()
        })
        equalSign.addEventListener('click', (e) => {
            equal.innerText = parseInt(newValue.innerText) + parseInt(newValue.innerText);
            value.style.display = 'none';
            newValue.style.display = 'none';
            operator.style.display = 'none';
        })
    })
})
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!