-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (28 loc) · 1.29 KB
/
script.js
File metadata and controls
33 lines (28 loc) · 1.29 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
const animals = [
{ name: "Elephant", clue: "I am the largest land animal." },
{ name: "Tiger", clue: "I am a big cat and have stripes." },
{ name: "Dolphin", clue: "I am a marine mammal and known for my intelligence." },
{ name: "Eagle", clue: "I am a bird of prey and have excellent vision." },
];
let currentAnimal;
let score = 0;
function startGame() {
currentAnimal = animals[Math.floor(Math.random() * animals.length)];
document.getElementById("clue").innerText = currentAnimal.clue;
document.getElementById("result").innerText = "";
document.getElementById("guess").value = "";
document.getElementById("next").style.display = "none";
}
document.getElementById("submit").addEventListener("click", function() {
const guess = document.getElementById("guess").value.trim();
if (guess.toLowerCase() === currentAnimal.name.toLowerCase()) {
document.getElementById("result").innerText = "Correct! 🎉";
score++;
document.getElementById("next").style.display = "block";
} else {
document.getElementById("result").innerText = `Wrong! The correct answer is ${currentAnimal.name}.`;
document.getElementById("next").style.display = "block";
}
});
document.getElementById("next").addEventListener("click", startGame);
startGame();