Net Run Rate (NRR) is a crucial statistic in cricket that measures a team's performance over a series or tournament. It is calculated by subtracting a team's average runs conceded per wicket from its average runs scored per wicket, and then multiplying the result by the number of overs played. A positive NRR indicates that the team is scoring runs faster than their opponents are conceding them, while a negative NRR suggests the opposite.
function calculateNRR() {
var totalRunsScored = parseFloat(document.getElementById("totalRunsScored").value);
var totalWicketsLost = parseFloat(document.getElementById("totalWicketsLost").value);
var totalBallsBowled = parseFloat(document.getElementById("totalBallsBowled").value);
var totalRunsConceded = parseFloat(document.getElementById("totalRunsConceded").value);
var totalWicketsTaken = parseFloat(document.getElementById("totalWicketsTaken").value);
var totalBallsPlayed = parseFloat(document.getElementById("totalBallsPlayed").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
// Input validation
if (isNaN(totalRunsScored) || isNaN(totalWicketsLost) || isNaN(totalBallsBowled) ||
isNaN(totalRunsConceded) || isNaN(totalWicketsTaken) || isNaN(totalBallsPlayed)) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
if (totalWicketsLost === 0 || totalBallsBowled === 0 || totalWicketsTaken === 0 || totalBallsPlayed === 0) {
resultDiv.innerHTML = "Wickets lost, wickets taken, and balls played/bowled cannot be zero for calculation.";
return;
}
// Calculate runs scored per wicket
var runsScoredPerWicket = totalRunsScored / totalWicketsLost;
// Calculate runs conceded per wicket
var runsConcededPerWicket = totalRunsConceded / totalWicketsTaken;
// Calculate NRR
var nrr = (runsScoredPerWicket – runsConcededPerWicket) * (totalBallsPlayed / 6); // Assuming 6 balls per over for simplicity, adjust if T20 specific or other formats needed
resultDiv.innerHTML = "