-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdlsCal.js
69 lines (58 loc) · 2.59 KB
/
dlsCal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
document.addEventListener("DOMContentLoaded", function () {
// DLS Calculator Input Handling
var dlsInputs = document.querySelectorAll(
"#teamAScore, #teamAWickets, #teamAExtraOvers, #teamBWickets"
);
dlsInputs.forEach(function (input) {
input.addEventListener("input", calculateDLS);
});
// Function to Calculate Duckworth Lewis Stern (DLS) Target
function calculateDLS() {
var teamAScore = parseInt(document.getElementById("teamAScore").value) || 0;
var teamAWickets =
parseInt(document.getElementById("teamAWickets").value) || 0;
var teamAExtraOvers =
parseFloat(document.getElementById("teamAExtraOvers").value) || 0;
var teamBWickets =
parseInt(document.getElementById("teamBWickets").value) || 0;
if (teamAWickets <= teamBWickets) {
var target = Math.floor((teamAScore * (20 - teamAExtraOvers)) / 20) + 1;
document.getElementById("dlsResult").value = target;
} else {
var adjustedTarget =
Math.floor((teamAScore * (20 - teamAExtraOvers)) / 20) + 4;
var wicketsDifference = teamAWickets - teamBWickets;
var additionalRuns = Math.floor(wicketsDifference / 2) + 4;
var finalTarget = adjustedTarget + additionalRuns;
document.getElementById("dlsResult").value = finalTarget;
}
}
// Call calculateDLS function on button click
document
.getElementById("dlsCalculateBtn")
.addEventListener("click", calculateDLS);
});
document.querySelector(".a1").addEventListener("mouseover", function () {
document.querySelector(".one").style.visibility = "visible";
});
document.querySelector(".a1").addEventListener("mouseout", function () {
document.querySelector(".one").style.visibility = "hidden";
});
document.querySelector(".b").addEventListener("mouseover", function () {
document.querySelector(".two").style.visibility = "visible";
});
document.querySelector(".b").addEventListener("mouseout", function () {
document.querySelector(".two").style.visibility = "hidden";
});
document.querySelector(".c").addEventListener("mouseover", function () {
document.querySelector(".three").style.visibility = "visible";
});
document.querySelector(".c").addEventListener("mouseout", function () {
document.querySelector(".three").style.visibility = "hidden";
});
document.querySelector(".d").addEventListener("mouseover", function () {
document.querySelector(".four").style.visibility = "visible";
});
document.querySelector(".d").addEventListener("mouseout", function () {
document.querySelector(".four").style.visibility = "hidden";
});