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

187
Views
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 answers
Answer question

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 Report

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 Report

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 Report
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!