diff --git a/Calculators/Cricket-Calculator/index.html b/Calculators/Cricket-Calculator/index.html index d65939853..5ced05ce6 100644 --- a/Calculators/Cricket-Calculator/index.html +++ b/Calculators/Cricket-Calculator/index.html @@ -64,8 +64,25 @@

Target

+ +
+

Net Run Rate Calculator

+ + + + + + + + + +

+
+ + + diff --git a/Calculators/Cricket-Calculator/script.js b/Calculators/Cricket-Calculator/script.js index 4f9251750..5155fabd6 100644 --- a/Calculators/Cricket-Calculator/script.js +++ b/Calculators/Cricket-Calculator/script.js @@ -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 = ""; + } + +} +