Run Rate Calculator Cricket

Cricket Run Rate Calculator

This calculator helps you determine the current run rate, required run rate, and projected total for a cricket match. Understanding run rates is crucial for strategizing in limited-overs cricket, as it directly impacts the required scoring pace to win.

function calculateRunRate() { var currentRuns = parseFloat(document.getElementById("currentRuns").value); var oversBowled = parseFloat(document.getElementById("oversBowled").value); var targetScore = parseFloat(document.getElementById("targetScore").value); var oversRemaining = parseFloat(document.getElementById("oversRemaining").value); var resultDiv = document.getElementById("result"); resultDiv.innerHTML = ""; // Clear previous results // Input validation if (isNaN(currentRuns) || isNaN(oversBowled) || isNaN(targetScore) || isNaN(oversRemaining) || currentRuns < 0 || oversBowled < 0 || targetScore < 0 || oversRemaining 0) { currentRunRate = currentRuns / oversBowledDecimal; } // Calculate Required Run Rate var runsNeeded = targetScore – currentRuns; var requiredRunRate = 0; if (oversRemainingDecimal > 0 && runsNeeded > 0) { requiredRunRate = runsNeeded / oversRemainingDecimal; } else if (runsNeeded 0) { projectedTotal = currentRuns + (currentRunRate * oversRemainingDecimal); } var htmlOutput = "

Match Stats:

"; htmlOutput += "Current Run Rate: " + currentRunRate.toFixed(2) + " runs per over"; if (runsNeeded > 0) { htmlOutput += "Runs Needed: " + runsNeeded + " runs"; htmlOutput += "Required Run Rate: " + requiredRunRate.toFixed(2) + " runs per over"; } else { htmlOutput += "Target achieved! No runs needed."; } htmlOutput += "Projected Total at Current Rate: " + projectedTotal.toFixed(0) + " runs"; resultDiv.innerHTML = htmlOutput; } .calculator-widget { font-family: Arial, sans-serif; border: 1px solid #ccc; padding: 20px; border-radius: 8px; max-width: 500px; margin: 20px auto; background-color: #f9f9f9; } .calculator-widget h2 { text-align: center; color: #333; margin-bottom: 20px; } .inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin-bottom: 20px; } .form-group { display: flex; flex-direction: column; } .form-group label { margin-bottom: 5px; font-weight: bold; color: #555; } .form-group input[type="number"] { padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 1rem; width: 100%; box-sizing: border-box; /* Include padding and border in the element's total width and height */ } .calculator-widget button { display: block; width: 100%; padding: 12px 20px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; font-size: 1.1rem; cursor: pointer; transition: background-color 0.3s ease; } .calculator-widget button:hover { background-color: #45a049; } .results { margin-top: 25px; padding: 15px; background-color: #e9e9e9; border-radius: 4px; border: 1px solid #ddd; } .results h3 { color: #333; margin-top: 0; } .results p { margin-bottom: 8px; color: #444; line-height: 1.5; } .results strong { color: #0066cc; }

Leave a Comment