-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice8.html
More file actions
202 lines (185 loc) · 5.92 KB
/
Copy pathpractice8.html
File metadata and controls
202 lines (185 loc) · 5.92 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dynamic Quiz Section</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: 'Segoe UI', sans-serif;
background: #f0f4ff;
margin: 0;
padding: 20px;
text-align: center;
}
h1, h2 {
color: #333;
}
.grid {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 20px;
margin-top: 30px;
}
.card {
background: white;
padding: 20px;
border-radius: 15px;
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
width: 200px;
cursor: pointer;
transition: 0.3s ease;
}
.card:hover {
background: #e0ecff;
transform: translateY(-5px);
}
.hidden {
display: none;
}
.back-btn {
margin-top: 20px;
background: #6c63ff;
color: white;
padding: 10px 20px;
border: none;
border-radius: 10px;
cursor: pointer;
}
.question {
margin-bottom: 20px;
text-align: left;
}
.submit-btn {
margin-top: 20px;
padding: 10px 20px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 10px;
cursor: pointer;
}
#result {
margin-top: 20px;
font-size: 18px;
font-weight: bold;
color: green;
}
#video-section {
margin-top: 40px;
}
video {
margin-top: 20px;
border: 2px solid #333;
border-radius: 10px;
}
</style>
</head>
<body>
<h1>Dynamic Quiz Section</h1>
<!-- Subject Selection -->
<div id="subject-section" class="grid">
<div class="card" onclick="showChapters('science')">Science</div>
<div class="card" onclick="showChapters('math')">Math</div>
<div class="card" onclick="showChapters('sst')">SST</div>
</div>
<!-- Chapters Section -->
<div id="chapter-section" class="hidden">
<h2 id="chapter-title"></h2>
<div id="chapter-list" class="grid"></div>
<button class="back-btn" onclick="goBackToSubjects()">Back to Subjects</button>
</div>
<!-- Quiz Section -->
<div id="quiz-section" class="hidden">
<h2 id="quiz-title"></h2>
<div id="quiz"></div>
<button class="submit-btn" onclick="submitQuiz()">Submit Quiz</button>
<div id="result"></div>
<button class="back-btn" onclick="goBackToChapters()">Back to Chapters</button>
</div>
<!-- Video Section -->
<div id="video-section">
<h2>Watch this video for help!</h2>
<p>If the video doesn't load, you can watch it <a href="YOUR_VIDEO_URL_HERE" target="_blank">here</a>.</p>
<video width="640" height="360" controls>
<source src="YOUR_VIDEO_URL_HERE" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
<script>
const chapters = {
science: {
title: "Science Chapters",
items: {
"Force and Pressure": [
{ q: "What is force?", options: ["Push or pull", "Motion", "Energy", "Power"], answer: 0 },
{ q: "Pressure depends on?", options: ["Mass", "Area", "Speed", "Volume"], answer: 1 }
],
"Crop Production": [
{ q: "What is the first step in crop production?", options: ["Harvesting", "Sowing", "Irrigation", "Manuring"], answer: 1 },
{ q: "What is used to plow soil?", options: ["Tractor", "Seed", "Water", "Pesticide"], answer: 0 }
]
}
},
};
function showChapters(subject) {
document.getElementById('subject-section').classList.add('hidden');
document.getElementById('chapter-section').classList.remove('hidden');
document.getElementById('quiz-section').classList.add('hidden');
const chapterData = chapters[subject];
document.getElementById('chapter-title').innerText = chapterData.title;
const chapterList = document.getElementById('chapter-list');
chapterList.innerHTML = '';
Object.entries(chapterData.items).forEach(([name, questions]) => {
const div = document.createElement('div');
div.className = 'card';
div.textContent = name;
div.onclick = () => startQuiz(name, questions);
chapterList.appendChild(div);
});
}
function startQuiz(chapter, questions) {
document.getElementById('chapter-section').classList.add('hidden');
document.getElementById('quiz-section').classList.remove('hidden');
document.getElementById('quiz-title').innerText = chapter;
const quizDiv = document.getElementById('quiz');
quizDiv.innerHTML = '';
questions.forEach((q, i) => {
const qDiv = document.createElement('div');
qDiv.classList.add('question');
qDiv.innerHTML = `<strong>Q${i + 1}: ${q.q}</strong><br>`;
q.options.forEach((opt, j) => {
qDiv.innerHTML += `
<label>
<input type="radio" name="q${i}" value="${j}" />
${opt}
</label><br>
`;
});
quizDiv.appendChild(qDiv);
});
}
function submitQuiz() {
let score = 0;
const quizTitle = document.getElementById('quiz-title').innerText;
const questions = chapters.science.items[quizTitle];
questions.forEach((q, i) => {
const selectedOption = document.querySelector(`input[name="q${i}"]:checked`);
if (selectedOption && parseInt(selectedOption.value) === q.answer) {
score++;
}
});
document.getElementById('result').innerText = `You scored ${score} out of ${questions.length}!`;
}
function goBackToSubjects() {
document.getElementById('chapter-section').classList.add('hidden');
document.getElementById('subject-section').classList.remove('hidden');
}
function goBackToChapters() {
document.getElementById('quiz-section').classList.add('hidden');
document.getElementById('chapter-section').classList.remove('hidden');
}
</script>
</body>
</html>