-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
77 lines (64 loc) · 3.84 KB
/
script.js
File metadata and controls
77 lines (64 loc) · 3.84 KB
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
const facts = {
0: { answer: true, reason: "Frog legs (cuisses de grenouille) are a traditional, albeit not daily, delicacy in French cuisine, particularly in eastern France." }, // France
1: { answer: true, reason: "It is generally true that tipping is not customary in China and can be considered rude, embarrassing, or akin to giving charity." }, // China
2: { answer: false, reason: "New laws effective October 1, 2024, make it mandatory for all bird keepers to register with the APHA, but a restrictive 'wild animal' license is not required." }, // United Kingdom
3: { answer: false, reason: "Guinea pigs are social animals and need company, which is why it is actually illegal in Switzerland to own just one." }, // Switzerland
4: { answer: false, reason: "While handshakes are common in business, a traditional greeting among close friends and family in the Netherlands is three kisses on alternating cheeks." }, // Nertherlands (or Holland as my book says)
5: { answer: true, reason: "The unicorn is the official national animal of Scotland, symbolizing strength and untamed power in Celtic mythology." }, // Scotland
6: { answer: false, reason: "In Sweden, it is generally considered impolite to enter a home while wearing outdoor shoes. Standard etiquette is to remove them." }, // Sweeden
7: { answer: false, reason: "While Danish love ice cream and consume it year-round, it is not a standard or frequent breakfast food." }, // Denmark
8: { answer: true, reason: "In Portugal, the name 'Lucifer' is legally prohibited for use on newborns." }, // Portugal
9: { answer: true, reason: "Most Austrians will stand and wait for the 'little green man' (Ampelmännchen) to appear, even if the street is empty." } // Austria
};
let userAnswers = {};
function checkAnswer(factId, answer, element) {
userAnswers[factId] = answer;
const buttons = element.parentElement.querySelectorAll('button');
buttons.forEach(btn => btn.classList.remove('active'));
element.classList.add('active');
}
function showResults() {
const totalFacts = Object.keys(facts).length;
const answeredCount = Object.keys(userAnswers).length;
if (answeredCount < totalFacts) {
document.getElementById('score-display').innerText = `Answer the questions first before you submit... (${answeredCount}/${totalFacts})`;
return;
}
let score = 0;
let resultsHTML = '';
for (let id in facts) {
const isCorrect = userAnswers[id] === facts[id].answer;
if (isCorrect) score++;
const factTitle = document.querySelectorAll('.fact h2')[id].innerText;
resultsHTML += `
<div class="result-item ${isCorrect ? 'correct' : 'wrong'}">
<h3>${factTitle}</h3>
<div class="user-answer ${isCorrect ? 'correct' : 'wrong'}">
Your answer: ${userAnswers[id] ? 'True' : 'False'} ${isCorrect ? '✓' : '✗'}
</div>
<div class="explanation">
<strong>Reason:</strong> ${facts[id].reason}
</div>
</div>
`;
}
// Showing the score
const display = document.getElementById('score-display');
display.innerText = `You got ${score} out of ${totalFacts} correct!`;
// Adding the detailed results
const resultsContainer = document.querySelector('.results');
let breakdown = document.getElementById('results-breakdown');
if (!breakdown) {
breakdown = document.createElement('div');
breakdown.id = 'results-breakdown';
resultsContainer.appendChild(breakdown);
}
breakdown.innerHTML = resultsHTML;
if (score === totalFacts) {
display.style.color = '#4ade80'; // Green
} else if (score >= totalFacts / 2) {
display.style.color = '#facc15'; // Yellow
} else {
display.style.color = '#f87171'; // Red
}
}