This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skeetTest.html
130 lines (119 loc) · 3.79 KB
/
skeetTest.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Skeet Scorecard</title>
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
th,
td {
padding: 10px;
text-align: center;
}
th {
background-color: lightgray;
}
td[contenteditable]:focus {
outline: 2px solid blue;
}
</style>
</head>
<body>
<h1>Skeet Scorecard</h1>
<label for="numShooters">Number of Shooters:</label>
<input type="number" id="numShooters" min="1" max="10" value="1" />
<label for="numStations">Number of Stations:</label>
<input type="number" id="numStations" min="1" max="10" value="5" />
<button onclick="generateScorecard()">Generate Scorecard</button>
<br /><br />
<div id="scorecard"></div>
<script>
function generateScorecard() {
const numShooters = document.getElementById("numShooters").value;
const numStations = document.getElementById("numStations").value;
const scorecard = document.createElement("table");
const headerRow = scorecard.insertRow();
headerRow.insertCell().textContent = "Shooter";
for (let i = 1; i <= numStations; i++) {
headerRow.insertCell().textContent = `Station ${i} - T1`;
headerRow.insertCell().textContent = `Station ${i} - T2`;
}
headerRow.insertCell().textContent = "Total";
for (let i = 1; i <= numShooters; i++) {
const shooterRow = scorecard.insertRow();
const shooterName = prompt(`Enter name for shooter ${i}:`);
shooterRow.insertCell().textContent = shooterName;
for (let j = 1; j <= numStations * 2; j++) {
const cell = shooterRow.insertCell();
cell.contentEditable = true;
cell.addEventListener("input", updateScores);
}
shooterRow.insertCell();
}
document.getElementById("scorecard").appendChild(scorecard);
}
function updateScores() {
const scorecard = document.querySelector("table");
for (let i = 1; i < scorecard.rows.length; i++) {
const shooterRow = scorecard.rows[i];
let total = 0;
for (let j = 1; j < shooterRow.cells.length - 1; j += 2) {
const target1 = shooterRow.cells[j].textContent.trim();
const target2 = shooterRow.cells[j + 1].textContent.trim();
if (target1.toLowerCase() === "x" || target2.toLowerCase() === "x") {
total++;
} else if (!isNaN(target1) && !isNaN(target2)) {
total += parseInt(target1) + parseInt(target2);
}
}
shooterRow.cells[shooterRow.cells.length - 1].textContent = total;
}
}
const scorecard = document.querySelector("table");
for (let i = 1; i < scorecard.rows.length; i++) {
const shooterRow = scorecard.rows[i];
for (let j = 1; j < shooterRow.cells.length - 1; j++) {
const cell = shooterRow.cells[j];
cell.contentEditable = true;
cell.addEventListener("input", updateScores);
}
}
function updateScores() {
const scorecard = document.querySelector("table");
for (let i = 1; i < scorecard.rows.length; i++) {
const shooterRow = scorecard.rows[i];
let total = 0;
let allScoresEntered = true;
for (let j = 1; j < shooterRow.cells.length - 1; j += 2) {
const target1 = shooterRow.cells[j].textContent.trim();
const target2 = shooterRow.cells[j + 1].textContent.trim();
let score1 = parseInt(target1);
let score2 = parseInt(target2);
if (target1.toLowerCase() === "x") {
score1 = 1;
}
if (target2.toLowerCase() === "x") {
score2 = 1;
}
if (isNaN(score1) || isNaN(score2)) {
allScoresEntered = false;
break;
}
total += score1 + score2;
}
if (allScoresEntered) {
shooterRow.cells[shooterRow.cells.length - 1].textContent = total;
} else {
shooterRow.cells[shooterRow.cells.length - 1].textContent = " ";
}
}
}
</script>
</body>
</html>