Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
Adding two outputs together

I got a profit calculator from a developer, which works perfectly, and I want to add the final result with the amount which has been typed in.

This is my code:

//////////PROFIT CALCULATOR

const numbers = document.querySelectorAll(".number");
const resultText = document.querySelector(".result");
let value, percent; // must be declared outside of the foreach

numbers.forEach((number) => {
  number.addEventListener("input", () => {
    if (number.classList.contains("value")) {
      value = parseFloat(number.value);
    }

    if (number.classList.contains("percent")) {
      percent = parseFloat(number.value);
    }

    if ((value || value == 0) && (percent || percent == 0)) {
      resultText.innerHTML = calculate(value, percent);
    }
  });
});

function calculate(val, percent) {
  return (val * percent) / 100;
}
<div class="percentage-calc">
  <div class="input_container">
    <span>Amount</span>
    <input type="number" class="number value">$
  </div>
  <div class="input_container">
    <span>Percent</span>
    <input type="number" class="number percent">% = $
    <span class="result"></span>
  </div>
</div>

Please I need help

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If I understood correctly, you want to add the result to the typed Amount.

Add the value to your calculate function :

function calculate(val, percent) {
    return (val * percent) / 100 + value;
}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda