-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscripts.js
148 lines (119 loc) · 4.45 KB
/
scripts.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
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
let slideIndex = 1;
let emailEntered = false;
let resultsShown = false;
showSlides();
function showSlides() {
let slides = document.getElementsByClassName("Slide");
let dots = document.getElementsByClassName("dot");
for (let i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for( let i = 0; i < dots.length; ++i) {
dots[i].className = dots[i].className.replace("active", "");
}
if (slideIndex > slides.length) {
slideIndex = 1;
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex - 1].className += " active";
slideIndex++;
setTimeout(showSlides, 7000);
}
function changeSlides(position) {
let slides = document.getElementsByClassName("Slide");
let dots = document.getElementsByClassName("dot");
slideIndex += position;
if (slideIndex > slides.length) {slideIndex = 1}
else if(slideIndex < 1){slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
function currentSlide(position) {
let slides = document.getElementsByClassName("Slide");
let dots = document.getElementsByClassName("dot");
if (position > slides.length) {position = 1}
else if(position < 1){position = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[position-1].style.display = "block";
dots[position-1].className += " active";
}
function validateEmail() {
let email = document.getElementsByClassName("textBox")[0].value;
let re = /^[a-zA-Z0-9. _-]+@[a-zA-Z0-9. -]+\. [a-zA-Z]{2,4}$/;
displayResponse(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email));
}
function displayResponse(isEmail) {
if (emailEntered){
let elem = document.getElementsByClassName("email")[0];
elem.remove();
}
let html = document.createElement("h4");
html.className = "email";
if (isEmail) {
var inner = document.createTextNode("You will recieve answer on your E-mail soon..");
}
else {
var inner = document.createTextNode("Invalid E-mail adress..");
}
html.appendChild(inner);
const appendAfter = document.getElementsByClassName("submitButton")[0]
appendAfter.parentNode.insertBefore(html, appendAfter.nextSibling);
emailEntered = true;
}
function SubmitTest() {
let score = 0;
let percentage = 0;
let questions = 6;
let answers = ["trall.mp3", "arthas_angry.mp3", "tuzad.mp3", "tirend.mp3", "mediv.mp3", "jaina.mp3"];
try {
for( let i = 0; i < questions; ++i){
let answerRadio = document.querySelector(`input[name="question${i + 1}"]:checked`);
let answered = answerRadio.nextElementSibling.childNodes[1].getAttribute("src"); // Returns sounds/*.mp3 of chosen answer
let answer = answered.split("/")[1]; // Returns second elemend of array (*.mp3) selected by user
if(answer == answers[i])
score ++;
}
percentage = score / questions * 100;
}
catch(TypeError) {
alert("You have not chosen all of the options!");
return;
}
ShowResults(score, percentage, questions );
}
function ShowResults(score, percentage, questions) {
if (resultsShown){
let elem = document.getElementsByClassName("results")[0];
elem.remove();
}
let message = "";
let str = `Your score is - ${score}/${questions}. Your percentage of correct answers is - ${percentage}% out of 100%. `
if (percentage >= 90){
message = "Wow. You know Warcraft 3 very well!"
}
else if (percentage >= 50) {
message = "You have certainly played Warcraft 3 a little bit."
}
else {
message = "Haven't you played Warcraft 3 yet?"
}
str += message;
str = document.createTextNode(str);
let html = document.createElement("h4");
html.appendChild(str);
html.className = "results";
const appendAfter = document.getElementsByName("lastQuestion")[0];
appendAfter.parentNode.insertBefore(html, appendAfter.nextSibling);
resultsShown = true;
}