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

312
Views
JS Calculator, results not showing up as intended?

Still learning JavaScript and I can't seem to figure out why my firstInput is doubling after doing a second number. Example, '1+' shows fine in the results screen, but when I click the secondInput to '2' hoping it comes out to 1+2, it instead shows me 112+2. Tried putting it into a stored input after making first input but still can't figure this out. Here is my code

https://codepen.io/Kaytin143/pen/bGRjQqx

let firstInput = '';
let storedInput = '';
let secondInput = '';
let currentOp = '';
const results_div = document.querySelector('.screen')
const numberBtns = document.querySelectorAll('.numbers')
numberBtns.forEach((numbers) => {
  numbers.addEventListener('click', () => {
    firstInput += numbers.value;
    storedInput += firstInput;
    results_div.innerHTML = firstInput;
    numberBtns.forEach((numbers) => {
      numbers.addEventListener('click', () => {
        secondInput += numbers.value;
        results_div.innerHTML = storedInput + currentOp + secondInput;
      })
    })
    //second Input
  })
})
// listeners for operators //
const operatorBtns = document.querySelectorAll('.operator');
const clearBtn = document.querySelector('.c');

operatorBtns.forEach((operators) => {
  operators.addEventListener('click', () => {
    currentOp += operators.value;
    results_div.innerHTML = firstInput + currentOp;
  })
})

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!