|
1 |
| -document.getElementById('quizForm').addEventListener('submit', function (e) { |
2 |
| - e.preventDefault(); |
3 |
| - |
4 |
| - // Store house points |
5 |
| - const housePoints = { |
6 |
| - Gryffindor: 0, |
7 |
| - Ravenclaw: 0, |
8 |
| - Hufflepuff: 0, |
9 |
| - Slytherin: 0 |
10 |
| - }; |
11 |
| - |
12 |
| - // Count the selected answers |
13 |
| - const form = new FormData(this); |
14 |
| - let attemptedQuestions = 0; // Track attempted questions |
15 |
| - |
16 |
| - for (let pair of form.entries()) { |
17 |
| - if (housePoints[pair[1]] !== undefined) { |
18 |
| - housePoints[pair[1]] += 1; |
19 |
| - attemptedQuestions++; // Increment for each attempted question |
20 |
| - } |
21 |
| - } |
| 1 | +document.getElementById("quizForm").addEventListener("submit", function (e) { |
| 2 | + e.preventDefault(); |
| 3 | + |
| 4 | + // Store house points |
| 5 | + const housePoints = { |
| 6 | + Gryffindor: 0, |
| 7 | + Ravenclaw: 0, |
| 8 | + Hufflepuff: 0, |
| 9 | + Slytherin: 0, |
| 10 | + }; |
22 | 11 |
|
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 |
| 12 | + // Count the selected answers |
| 13 | + const form = new FormData(this); |
| 14 | + let attemptedQuestions = 0; // Track attempted questions |
| 15 | + |
| 16 | + for (let pair of form.entries()) { |
| 17 | + if (housePoints[pair[1]] !== undefined) { |
| 18 | + housePoints[pair[1]] += 1; |
| 19 | + attemptedQuestions++; // Increment for each attempted question |
28 | 20 | }
|
| 21 | + } |
| 22 | + |
| 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 | + |
| 30 | + // Determine the house with the highest points |
| 31 | + let assignedHouse = Object.keys(housePoints).reduce((a, b) => |
| 32 | + housePoints[a] > housePoints[b] ? a : b |
| 33 | + ); |
| 34 | + |
| 35 | + // House descriptions |
| 36 | + const houseDescriptions = { |
| 37 | + Gryffindor: |
| 38 | + "You have been sorted into Gryffindor, the house of the brave and daring! Known for their courage, Gryffindors are always ready to stand up for what is right, no matter the odds. With a bold heart and a fierce sense of justice, you are never afraid to take risks or face challenges head-on. Welcome to the house of heroes like Harry Potter, Hermione Granger, and Albus Dumbledore!", |
| 39 | + Ravenclaw: |
| 40 | + "Welcome to Ravenclaw, where wisdom and learning are prized above all! As a member of this house, you are valued for your intelligence, creativity, and curiosity. Ravenclaws are known for their sharp minds and thirst for knowledge, always seeking answers to life’s mysteries. You join the ranks of greats like Luna Lovegood and Cho Chang, where cleverness and ingenuity reign supreme!", |
| 41 | + Hufflepuff: |
| 42 | + "You’ve been sorted into Hufflepuff, the house of loyalty and kindness! Hufflepuffs are known for their strong sense of fairness, patience, and dedication. You are someone who values friendship, hard work, and the well-being of others. In Hufflepuff, every person matters, and unity is key. You stand alongside legends like Newt Scamander and Cedric Diggory, where inclusivity and perseverance define your strength!", |
| 43 | + Slytherin: |
| 44 | + "Welcome to Slytherin, where ambition and cunning pave the way to greatness! As a Slytherin, you are driven by your goals and never shy away from doing what it takes to succeed. Known for being resourceful and strategic, you can navigate challenges with ease and foresight. In Slytherin, you follow in the footsteps of powerhouses like Severus Snape and Merlin, with ambition as your guiding star!", |
| 45 | + }; |
| 46 | + |
| 47 | + // House images |
| 48 | + const houseImages = { |
| 49 | + Gryffindor: |
| 50 | + "https://i.pinimg.com/564x/20/32/4c/20324c7839e5f076e7a3d5baa7b77f62.jpg", |
| 51 | + Ravenclaw: |
| 52 | + "https://i.pinimg.com/564x/92/b5/65/92b5654268d9f3157ed1ec58f6d63c3e.jpg", |
| 53 | + Hufflepuff: |
| 54 | + "https://i.pinimg.com/564x/66/ba/0c/66ba0cd629a306ecf9d207c90d2184be.jpg", |
| 55 | + Slytherin: |
| 56 | + "https://i.pinimg.com/564x/c1/4f/36/c14f36dea82449f6ee5af5c2a6007c66.jpg", |
| 57 | + }; |
| 58 | + |
| 59 | + // Display result |
| 60 | + const resultDiv = document.getElementById("result"); |
| 61 | + resultDiv.innerHTML = `🎉 You belong to <strong>${assignedHouse}</strong>!<br>${houseDescriptions[assignedHouse]}`; |
| 62 | + |
| 63 | + // Display the house image |
| 64 | + const houseImage = document.getElementById("houseImage"); |
| 65 | + houseImage.src = houseImages[assignedHouse]; |
| 66 | + houseImage.alt = `${assignedHouse} logo`; |
| 67 | + houseImage.style.display = "block"; |
| 68 | +}); |
| 69 | + |
| 70 | +const spells = [ |
| 71 | + "Expecto Patronum", |
| 72 | + "Alarte Ascendare", |
| 73 | + "Avada Kedavra", |
| 74 | + "Accio", |
| 75 | + "Stupefy", |
| 76 | + "Wingardium Leviosa", |
| 77 | + "Alohomora", |
| 78 | +]; |
| 79 | + |
| 80 | +function getSpellOfTheDay() { |
| 81 | + const currentDate = new Date(); |
| 82 | + const dayOfYear = getDayOfYear(currentDate); |
| 83 | + |
| 84 | + const spellIndex = dayOfYear % spells.length; |
| 85 | + return spells[spellIndex]; |
| 86 | +} |
| 87 | + |
| 88 | +// Helper function to get the current day of the year (1 - 365) |
| 89 | +function getDayOfYear(date) { |
| 90 | + const start = new Date(date.getFullYear(), 0, 0); |
| 91 | + const diff = |
| 92 | + date - |
| 93 | + start + |
| 94 | + (start.getTimezoneOffset() - date.getTimezoneOffset()) * 60 * 1000; |
| 95 | + const oneDay = 1000 * 60 * 60 * 24; |
| 96 | + return Math.floor(diff / oneDay); |
| 97 | +} |
| 98 | + |
| 99 | +document.getElementById("generateSpellBtn").addEventListener("click", () => { |
| 100 | + const spellTextElement = document.getElementById("spellText"); |
| 101 | + const randomSpell = getSpellOfTheDay(); |
29 | 102 |
|
30 |
| - // Determine the house with the highest points |
31 |
| - let assignedHouse = Object.keys(housePoints).reduce((a, b) => housePoints[a] > housePoints[b] ? a : b); |
32 |
| - |
33 |
| - // House descriptions |
34 |
| - const houseDescriptions = { |
35 |
| - Gryffindor: "You have been sorted into Gryffindor, the house of the brave and daring! Known for their courage, Gryffindors are always ready to stand up for what is right, no matter the odds. With a bold heart and a fierce sense of justice, you are never afraid to take risks or face challenges head-on. Welcome to the house of heroes like Harry Potter, Hermione Granger, and Albus Dumbledore!", |
36 |
| - Ravenclaw: "Welcome to Ravenclaw, where wisdom and learning are prized above all! As a member of this house, you are valued for your intelligence, creativity, and curiosity. Ravenclaws are known for their sharp minds and thirst for knowledge, always seeking answers to life’s mysteries. You join the ranks of greats like Luna Lovegood and Cho Chang, where cleverness and ingenuity reign supreme!", |
37 |
| - Hufflepuff: "You’ve been sorted into Hufflepuff, the house of loyalty and kindness! Hufflepuffs are known for their strong sense of fairness, patience, and dedication. You are someone who values friendship, hard work, and the well-being of others. In Hufflepuff, every person matters, and unity is key. You stand alongside legends like Newt Scamander and Cedric Diggory, where inclusivity and perseverance define your strength!", |
38 |
| - Slytherin: "Welcome to Slytherin, where ambition and cunning pave the way to greatness! As a Slytherin, you are driven by your goals and never shy away from doing what it takes to succeed. Known for being resourceful and strategic, you can navigate challenges with ease and foresight. In Slytherin, you follow in the footsteps of powerhouses like Severus Snape and Merlin, with ambition as your guiding star!" |
39 |
| - }; |
40 |
| - |
41 |
| - // House images |
42 |
| - const houseImages = { |
43 |
| - Gryffindor: "https://i.pinimg.com/564x/20/32/4c/20324c7839e5f076e7a3d5baa7b77f62.jpg", |
44 |
| - Ravenclaw: "https://i.pinimg.com/564x/92/b5/65/92b5654268d9f3157ed1ec58f6d63c3e.jpg", |
45 |
| - Hufflepuff: "https://i.pinimg.com/564x/66/ba/0c/66ba0cd629a306ecf9d207c90d2184be.jpg", |
46 |
| - Slytherin: "https://i.pinimg.com/564x/c1/4f/36/c14f36dea82449f6ee5af5c2a6007c66.jpg" |
47 |
| - }; |
48 |
| - |
49 |
| - // Display result |
50 |
| - const resultDiv = document.getElementById('result'); |
51 |
| - resultDiv.innerHTML = `🎉 You belong to <strong>${assignedHouse}</strong>!<br>${houseDescriptions[assignedHouse]}`; |
52 |
| - |
53 |
| - // Display the house image |
54 |
| - const houseImage = document.getElementById('houseImage'); |
55 |
| - houseImage.src = houseImages[assignedHouse]; |
56 |
| - houseImage.alt = `${assignedHouse} logo`; |
57 |
| - houseImage.style.display = 'block'; |
| 103 | + // Clear previous spell and reset animation |
| 104 | + spellTextElement.style.animation = "none"; |
| 105 | + setTimeout(() => { |
| 106 | + spellTextElement.textContent = randomSpell; |
| 107 | + spellTextElement.style.animation = ""; |
| 108 | + }, 10); // Small delay to trigger reflow and restart animation |
58 | 109 | });
|
0 commit comments