-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (38 loc) · 1.25 KB
/
Copy pathapp.js
File metadata and controls
44 lines (38 loc) · 1.25 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
const QBox = document.getElementById("Qbox");
const hintButton = document.getElementById("question_mark");
const hintBox = document.getElementById("hint-box");
const generateButton = document.getElementById("generate");
let questionsData = [];
let currentQuestion = null;
function getQues() {
fetch("questions.json")
.then((response) => response.json())
.then((data) => {
questionsData = data;
})
.catch((error) => console.error("Error loading questions:", error));
}
function setQues() {
if (questionsData.length === 0) return;
const randomIndex = Math.floor(Math.random() * questionsData.length);
currentQuestion = questionsData[randomIndex];
QBox.querySelector("p").innerText = currentQuestion.question;
hintBox.style.display = "none";
}
function showHint() {
if (currentQuestion) {
hintBox.innerHTML = `<p><strong>HINT:</strong> ${currentQuestion.hint}</p>`;
hintBox.style.display = "block";
}
}
generateButton.addEventListener("click", setQues);
hintButton.addEventListener("click", showHint);
getQues();
// const hint = document.getElementById("hint-box");
// function toggleHint() {
// if (hint.style.display === "none") {
// hint.style.display = "block";
// } else {
// hint.style.display = "none";
// }
// }