-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
119 lines (114 loc) · 3.4 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>HTML Quiz</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<style>
body {
background: linear-gradient(45deg, #fe6b8b, #f77062, #e6774c, #d7823f, #ca8a3b);
color: #FFF;
font-family: Arial, sans-serif;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.quiz {
width: 500px;
padding: 30px;
background-color: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 20px;
box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
text-align: center;
}
h1 {
font-size: 36px;
margin-bottom: 30px;
text-shadow: 2px 2px 5px #000;
}
label {
display: block;
font-size: 24px;
margin-bottom: 10px;
text-shadow: 2px 2px 5px #000;
}
input[type="radio"] {
transform: scale(1.5);
margin-right: 10px;
}
.btn {
display: inline-block;
padding: 12px 24px;
font-size: 20px;
font-weight: bold;
color: #FFF;
background-color: rgba(255, 255, 255, 0.2);
border: none;
border-radius: 5px;
cursor: pointer;
box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}
.btn:hover {
background-color: rgba(255, 255, 255, 0.3);
}
.result {
font-size: 24px;
margin-top: 20px;
text-shadow: 2px 2px 5px #000;
}
.correct {
color: #33FF69;
}
.incorrect {
color: #FF3366;
}
</style>
</head>
<body>
<div class="quiz">
<h1>HTML Quiz</h1>
<form id="quiz-form">
<label for="q1">1. What does HTML stand for?</label><br>
<input type="radio" name="q1" value="a"> Hypertext Markup Language<br>
<input type="radio" name="q1" value="b"> High-Tech Markup Language<br>
<input type="radio" name="q1" value="c"> Hyperlinking Text Markup Language<br><br>
<label for="q2">2. Which tag is used to create a hyperlink?</label><br>
<input type="radio" name="q2" value="a"> <a><br>
<input type="radio" name="q2" value="b"> <img><br>
<input type="radio" name="q2" value="c"> <div><br><br>
<label for="q3">3. Which tag is used to create a list with bullet points?</label><br>
<input type="radio" name="q3" value="a"> <ol><br>
<input type="radio" name="q3" value="b"> <li><br>
<input type="radio" name="q3" value="c"> <ul><br><br>
<button type="submit" class="btn"><i class="fas fa-check"></i> Submit Answers</button>
</form>
<div id="result" class="result"></div>
</div>
<script>
const form = document.getElementById('quiz-form');
const resultDiv = document.getElementById('result');
const correctAnswers = ['a', 'a', 'c'];
form.addEventListener('submit', e => {
e.preventDefault();
let score = 0;
const userAnswers = [form.q1.value, form.q2.value,
form.q3.value];
userAnswers.forEach((answer, index) => {
if (answer === correctAnswers[index]) {
score += 1;
}
});
resultDiv.innerHTML = `You got ${score} out of ${correctAnswers.length} questions correct!`;
const results = document.querySelectorAll('input[type="radio"]:checked');
results.forEach(result => {
if (result.value === correctAnswers[results.indexOf(result)]) {
result.parentElement.classList.add('correct');
} else {
result.parentElement.classList.add('incorrect');
}
});
});
</script>
</body>
</html>