Skip to content

Commit

Permalink
Added net run rate calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashish-1020 committed May 23, 2024
1 parent ded4fe2 commit d007c52
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Calculators/Cricket-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,25 @@ <h3>Target</h3>
<p id="target-result"></p>
</div>
</div>

<div class="calculator net-runrate">
<h3>Net Run Rate Calculator</h3>
<label for="runs-scored">Run Scored:</label>
<input type="number" id="runsScored" name="runs-scored" min="0" required>
<label for="overs-played">Overs Played:</label>
<input type="number" id="oversPlayed" name="overs-played" min="0" required>
<label for="runs-conceded">Run Conceded:</label>
<input type="number" id="runsConceded" name="runs-conceded" min="0" required>
<label for="overs-bowled">Overs Bowled:</label>
<input type="number" id="oversBowled" name="overs-bowled" min="0" required>
<button onclick="calculateRunRate()">Calculate</button>
<p id="net-runrate-result"></p>
</div>


</div>


<script src="script.js"></script>

</body>
Expand Down
20 changes: 20 additions & 0 deletions Calculators/Cricket-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,23 @@ function calculateTarget() {
oppositionScoreInput.value = "";
}
}


function calculateRunRate() {
var runsScored = parseInt(document.getElementById("runsScored").value);
var oversPlayed = parseInt(document.getElementById("oversPlayed").value);
var runsConceded = parseInt(document.getElementById("runsConceded").value);
var oversBowled = parseInt(document.getElementById("oversBowled").value);

if (!isNaN(runsScored) && !isNaN(oversPlayed) && !isNaN(runsConceded) &&!isNaN(oversBowled) ) {
var netRunRate = ((runsScored / oversPlayed) - (runsConceded / oversBowled)).toFixed(2);

document.getElementById("net-runrate-result").innerHTML = "Net Run Rate: " + netRunRate;
} else {
alert("Please enter all required details.");
// Clear input field if invalid input is detected
oppositionScoreInput.value = "";
}

}

0 comments on commit d007c52

Please sign in to comment.