Skip to content

Commit 2b3e91d

Browse files
authored
Merge pull request #17 from d-coder111/d-coder111-patch-1
Update script.js after correcting sorted button logic
2 parents 9923e93 + b7046a4 commit 2b3e91d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

script.js

+10
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ document.getElementById('quizForm').addEventListener('submit', function (e) {
1111

1212
// Count the selected answers
1313
const form = new FormData(this);
14+
let attemptedQuestions = 0; // Track attempted questions
15+
1416
for (let pair of form.entries()) {
1517
if (housePoints[pair[1]] !== undefined) {
1618
housePoints[pair[1]] += 1;
19+
attemptedQuestions++; // Increment for each attempted question
1720
}
1821
}
1922

23+
// Check if any questions were attempted
24+
if (attemptedQuestions === 0) {
25+
const resultDiv = document.getElementById('result');
26+
resultDiv.innerHTML = "You're out of Hogwarts!";
27+
return; // Stop execution if no questions were attempted
28+
}
29+
2030
// Determine the house with the highest points
2131
let assignedHouse = Object.keys(housePoints).reduce((a, b) => housePoints[a] > housePoints[b] ? a : b);
2232

0 commit comments

Comments
 (0)