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

177
Visualizações
The code i have written doesnt show results on input percentage

Hi im trying to calculate the percentage of 2 inputs but its not showing results can anyone tell me whats the problem

var Shots = document.getElementById("shots").value;
var Makes = document.getElementById("makes").value;

var results = (Makes / Shots) * 100;

function perqindja() {
    document.getElementById("answer").innerHTML = results;
};
<h2>Calculate your shots</h2>
<p>Type the number of shots taken:</p>
<input type="number" name="Shots" id="shots">
<p>Type the number of shots made:</p>           
<input type="number" name="Makes" id="makes">
<button onclick="Calculate()">Calculate</button>
<p>The shot percentage:<span id="answer"></span></p>

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You should define the variable inside the function so that it could store the input value after user click the button. Also, you doesn't define the Calculate(). I remove the perqindja() since I don't find it user in the code.

function Calculate() {
        var Shots = document.getElementById("shots").value;
var Makes = document.getElementById("makes").value;

var results = (Makes / Shots) * 100;

    document.getElementById("answer").innerHTML = results;
};
<p>Type the number of shots taken:</p>
<input type="number" name="Shots" id="shots">
<p>Type the number of shots made:</p>           
<input type="number" name="Makes" id="makes">
<button onclick="Calculate()">Calculate</button>
<p>The shot percentage:<span id="answer"></span></p>

about 4 years ago · Juan Pablo Isaza Relatório

0

The first problem is that the function Calculate is not defined. By the way, in javascript it is a good practice to give function lower case names. Second, you need to pass values to the calculate function.

Everything should work once you fix these 2 issues.

about 4 years ago · Juan Pablo Isaza Relatório

0

Your functions name is ‘perqindja()’ but you try to call ‘ Calculate()’ function on click in your html

about 4 years ago · Juan Pablo Isaza 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