This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathsample-quiz.html
170 lines (164 loc) · 6.47 KB
/
sample-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
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
<!DOCTYPE html>
<html>
<head>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<meta charset="utf-8">
<style>
body {
font-family: sans-serif;
}
code, pre {
font-family: monospace;
}
h1 code,
h2 code,
h3 code,
h4 code,
h5 code,
h6 code {
font-size: inherit;
}
ul li {
list-style-type: none;
}
table {
@extend .table;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="form-row">
<div class="container">
<h1>Servian Quiz</h1>
<hr>
<ol>
<li>
<p>Servian is a consultancy company.</p>
<ul class="radio-list">
<li><label><input type="radio" data-question="0" data-content="1" /> True</label></li>
<li><label><input type="radio" data-question="1" data-content="0" /> False</label></li>
</ul>
</li>
<li>
<p>Hashiqube was created at Servian.</p>
<ul class="radio-list">
<li><label><input type="radio" data-question="0" data-content="1" /> True</label></li>
<li><label><input type="radio" data-question="1" data-content="0" /> False </label></li>
</ul>
</li>
<li>
<p>Which Hashicorp products can you test or demo with Hashiqube?</p>
<ul class="checklist">
<li><label><input type="checkbox" data-question="1" data-content="0" /> Terraform</label></li>
<li><label><input type="checkbox" data-question="1" data-content="0" /> Vault</label></li>
<li><label><input type="checkbox" data-question="1" data-content="0" /> Consul</label></li>
<li><label><input type="checkbox" data-question="1" data-content="0" /> Nomad</label></li>
<li><label><input type="checkbox" data-question="1" data-content="0" /> Vagrant</label></li>
<li><label><input type="checkbox" data-question="1" data-content="0" /> Packer</label></li>
<li><label><input type="checkbox" data-question="1" data-content="0" /> Waypoint</label></li>
<li><label><input type="checkbox" data-question="1" data-content="0" /> Boundary</label></li>
<li><label><input type="checkbox" data-question="0" data-content="1" /> All of the above</label></li>
</ul>
</li>
<li>
<p>Who created Hashiqube?</p>
<ul class="textbox">
<li><input type="text" data-content="naloN naaiR" data-question="nsaslsosNs snsasasisRs" placeholder="Enter the correct answer." class="form-control" />
</ul>
</li>
</ol>
</div>
</div>
<div id="tg-msg" class="alert" role="alert" style="display: none">
<span id="tg-correct-questions"></span> Correct! <br /><b>Rating: <span id="tg-score"></span>%</b>
</div>
<div class="row">
<button id="check-questions" class="btn btn-lg btn-success">Check</button>
<button id="reset-questions" class="btn btn-link">Reset All</button>
</div>
<script type="text/javascript">$(function(){
$('ul.radio-list,ul.checklist,ul.textbox').each(function(i, el){
var questionClass = $(this).attr('class');
$(this).parent().addClass('question-row').addClass(questionClass);
if (questionClass=='radio-list') {
$(this).find('input[type="radio"]').attr('name', 'radio-question-' + i);
}
});
function checkQuestion() {
resetQuestions(true);
var questions = $('li.question-row');
var total_questions = questions.length;
var correct = 0;
questions.each(function(i, el) {
var self = $(this);
// Single Question.
if (self.hasClass('radio-list')) {
if (self.find('input[type="radio"][data-content="1"]:checked').length == 1) {
correct += 1;
} else {
self.addClass('text-danger');
}
}
// Textbox Question.
if(self.hasClass('textbox')) {
var textbox = self.find('input[type="text"]');
var correct_text = String(textbox.data("content")).trim().split("").reverse().join("");
if(String(textbox.val()).trim().toLowerCase()==correct_text.toLowerCase()) {
correct += 1;
} else {
self.addClass('text-danger');
textbox.parent().find("i.text-correct").html(correct_text);
}
}
// Multiple selection Questions.
if(self.hasClass('checklist')) {
var total_corrects = self.find('input[type="checkbox"][data-content="1"]').length;
var total_incorrects = self.find('input[type="checkbox"][data-content="0"]').length;
var correct_selected = self.find('input[type="checkbox"][data-content="1"]:checked').length;
var incorrect_selected = self.find('input[type="checkbox"][data-content="0"]:checked').length;
var qc = +((correct_selected / total_corrects) - (incorrect_selected/total_incorrects)).toFixed(2);
if (qc < 0) {
qc = 0;
}
correct += qc;
if (qc == 0) {
self.addClass('text-danger');
} else if (qc > 0 && qc < 1) {
self.addClass('text-warning');
}
}
});
showScore(correct, total_questions);
}
function showScore(correct, total) {
var score = (correct / total).toFixed(2) * 100;
var msgClass = 'alert-danger';
if (score >= 70) {
msgClass = 'alert-success';
} else if (score >= 50) {
msgClass = 'alert-warning';
}
$('#tg-correct-questions').text(correct + ' out of ' + total);
$('#tg-score').text(score);
$('#tg-msg').addClass(msgClass).show();
}
function resetQuestions(keep) {
$('li.question-row').removeClass('text-danger').removeClass('text-warning');
$('i.text-correct').html('');
$('#tg-msg').removeClass('alert-danger').removeClass('alert-success').removeClass('alert-warning').hide();
if(keep === true) {
return;
}
$('li.question-row').find('input[type="text"]').val('');
$('li.question-row').find('input[type="radio"],input[type="checkbox"]').prop('checked', false);
}
$('#check-questions').on('click', checkQuestion);
$('#reset-questions').on('click', resetQuestions);
});</script>
</div>
</body>
</html>