Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
92 lines (76 loc) · 3.11 KB
/
Copy pathscript.js
File metadata and controls
92 lines (76 loc) · 3.11 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
console.log("✅ script.js loaded");
// === QUIZ QUESTIONS ===
const questions = [
{ question: "What is Bitcoin?", answers: ["A blockchain", "A car", "A food", "A company"], correct: 0 },
{ question: "What does NFT stand for?", answers: ["Non-Fungible Token", "Network File Transfer", "New Financial Tool", "Node Functional Type"], correct: 0 },
{ question: "Which blockchain is known for smart contracts?", answers: ["Bitcoin", "Ethereum", "Dogecoin", "Ripple"], correct: 1 },
{ question: "What is the symbol for Ethereum?", answers: ["ETH", "ETC", "EHT", "EMT"], correct: 0 },
{ question: "Who created Bitcoin?", answers: ["Vitalik Buterin", "Satoshi Nakamoto", "Elon Musk", "CZ Binance"], correct: 1 },
];
let currentQuestion = 0;
let score = 0;
// === MAIN QUIZ LOGIC ===
function showQuestion() {
// 🟣 Quiz görünür hale getir
document.getElementById("quiz-box").style.display = "block";
document.getElementById("start-btn").style.display = "none";
document.getElementById("result-box").style.display = "none";
// 🟣 Soru ve cevapları göster
const questionData = questions[currentQuestion];
const questionEl = document.getElementById("question");
const answersEl = document.getElementById("answers");
const nextBtn = document.getElementById("next-btn");
questionEl.innerText = questionData.question;
answersEl.innerHTML = "";
questionData.answers.forEach((answer, i) => {
const btn = document.createElement("button");
btn.innerText = answer;
btn.classList.add("answer-btn");
btn.onclick = () => checkAnswer(i);
answersEl.appendChild(btn);
});
nextBtn.style.display = "none";
}
// === CHECK ANSWER ===
function checkAnswer(index) {
const questionData = questions[currentQuestion];
const nextBtn = document.getElementById("next-btn");
// ✅ Doğru cevapsa puan artır
if (index === questionData.correct) {
score++;
}
// ✅ Seçilen cevabı renklendir
const buttons = document.querySelectorAll(".answer-btn");
buttons.forEach((btn, i) => {
if (i === questionData.correct) {
btn.style.backgroundColor = "#4CAF50"; // yeşil
btn.style.color = "#fff";
} else if (i === index) {
btn.style.backgroundColor = "#E74C3C"; // kırmızı
btn.style.color = "#fff";
}
btn.disabled = true;
});
// ✅ “Next” butonunu göster
nextBtn.style.display = "block";
}
// === NEXT QUESTION BUTTON ===
document.getElementById("next-btn").addEventListener("click", () => {
currentQuestion++;
if (currentQuestion < questions.length) {
showQuestion();
} else {
showResults();
}
});
// === SHOW RESULTS ===
function showResults() {
document.getElementById("quiz-box").style.display = "none";
document.getElementById("result-box").style.display = "block";
document.getElementById("daily-score").innerText = score;
// 💾 Sonuçları localStorage’a kaydet (isteğe bağlı)
localStorage.setItem("lastScore", score);
console.log("🎉 Quiz tamamlandı! Skor:", score);
}
// === EXPORT GLOBAL ===
window.showQuestion = showQuestion;