-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.html
112 lines (108 loc) · 3.72 KB
/
quiz.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="main.css" />
<title>Triangle Quiz</title>
</head>
<body>
<div class="heading">
<a href="index.html"> <button class="button goback">Go Back</button></a>
<h3>Triangle Quiz</h3>
</div>
<div class="container tQuiz" style="text-align: center;display: flex;justify-content: center;">
<form class="quiz-form">
<div class="question-container">
<p>
A triangle sides with length: 35, 46 and 44. What kind of a triangle
is this?
</p>
<label
><input
type="radio"
name="question1"
id=""
value="Equilateral"
/>Equilateral</label
><label
><input
type="radio"
name="question1"
id=""
value="Isosceles"
/>Isosceles</label
><label><input type="radio"
name="question1"
id=""
value="Scalene"
/>Scalene</label
>
</div>
<div class="question-container">
<p>
A triangle has angles: 45, 45 and 90. Is this a right angled
triangle?
</p>
<label
><input type="radio" name="question2" id="" value="Yes" />Yes</label
><label
><input type="radio" name="question2" id="" value="No" />No</label
>
</div>
<div class="question-container">
<p>
A triangle has angles : 60, 60, 60. Is it an equilateral triangle?
</p>
<label
><input type="radio" name="question3" id="" value="Yes" />Yes</label
><label
><input type="radio" name="question3" id="" value="No" />No</label
>
</div>
<div class="question-container">
<p>
A triangle can have
</p>
<label
><input type="radio" name="question4" id="" value="one" />one right angle</label
><label
><input type="radio" name="question4" id="" value="two" />two right angles</label
>
</div>
<div class="question-container">
<p>
Which of the following can form a right angle triangle?
</p>
<label
><input type="radio" name="question5" id="" value="correct" />14,15,26</label
><label
><input type="radio" name="question5" id="" value="wrong" />12,16,20</label
>
</div>
</form>
</div>
<button id="submit" style="margin:auto;border-radius: 1rem;display:flex;justify-content: center;text-align:center;padding: 0.5rem;width: 6rem;center: pointer;background-color: lightcoral;">Submit</button>
<div class="output" style="text-align: center;color: white;"></div>
<script>
const quizForm = document.querySelector(".quiz-form");
const submit = document.querySelector("#submit");
const output = document.querySelector(".output");
const correctAnswers = ["Scalene", "Yes", "Yes", "one", "wrong"];
function checkAnswers() {
let score = 0;
let index = 0;
const formResults = new FormData(quizForm);
for (let value of formResults.values()) {
if (value === correctAnswers[index]) {
score++;
}
index++;
}
output.innerHTML = `<p>You scored ${score} points.</p>`;
}
submit.addEventListener("click", checkAnswers);
</script>
</body>
</html>