-
Notifications
You must be signed in to change notification settings - Fork 0
/
aptitude.js
70 lines (66 loc) · 2.14 KB
/
aptitude.js
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
var submitBtn = document.getElementById("submitBtn");
var resetBtn = document.getElementById("resetBtn");
var alertModal = document.getElementById("alertModal");
var alertMsg = document.getElementById("alertMsg");
var modalBtn = document.querySelector(".modal-btn");
var ans1 = document.getElementById("1d");
var ans2 = document.getElementById("2c");
var ans3 = document.getElementById("3b");
var ans4 = document.getElementById("4c");
var ans5 = document.getElementById("5b");
var ans6 = document.getElementById("6d");
var ans7 = document.getElementById("7b");
var ans8 = document.getElementById("8a");
var ans9 = document.getElementById("9b");
var ans10 = document.getElementById("10b");
var ans = [ans1, ans2, ans3, ans4, ans5, ans6, ans7, ans8, ans9, ans10];
var score = 0;
var checked = 0;
var percentage = 0;
var msg;
var buttons = document.getElementsByTagName("input");
function reset() {
score = 0;
checked = 0;
percentage = 0;
}
submitBtn.addEventListener("click", function() {
for (var i = 0; i < buttons.length; i++) {
if (buttons[i].checked) {
checked++;
}
}
if (checked) {
for (var i = 0; i < ans.length; i++) {
if (ans[i].checked) {
score++;
}
}
percentage = (score / 10) * 100;
// console.log(percentage);
if (percentage >= 70) {
msg = "Congratulations! You cleared the test.";
alertMsg.textContent = msg;
$('#alertModal').modal('show');
// modalBtn.addEventListener("click", function() {
// window.location = "CollisionCoding.html";
// });
} else {
msg = "You lost the game.";
alertMsg.textContent = msg;
$('#alertModal').modal('show');
//alertModal.modal('show');
}
} else {
msg = "Select options to proceed.";
alertMsg.textContent = msg;
$('#alertModal').modal('show');
//alertModal.modal('show');
}
reset();
});
resetBtn.addEventListener("click", function() {
for (var i = 0; i < buttons.length; i++) {
buttons[i].checked = false;
}
});