-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
147 lines (112 loc) · 6.94 KB
/
script.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
function reactionValidation() {
const reactionValue = document.getElementById("reactionValue").value;
if(reactionValue == "" || reactionValue > 100 || reactionValue < 0){
document.getElementById("reactionValue").style.border = '2px solid red';
document.getElementById("reactionValue").style.borderRadius = '5px';
}
else{
document.getElementById("reactionValue").style.border = 'none';
}
}
document.querySelector("button").addEventListener("click", () => reactionValidation())
function memoryValidation() {
const memoryValue = document.getElementById("memoryValue").value;
if(memoryValue == "" || memoryValue > 100 || memoryValue < 0){
document.getElementById("memoryValue").style.border = '2px solid red';
document.getElementById("memoryValue").style.borderRadius = '5px';
}
else{
document.getElementById("memoryValue").style.border = 'none';
}
}
document.querySelector("button").addEventListener("click", () => memoryValidation());
function verbalValidation() {
const verbalValue = document.getElementById("verbalValue").value;
if(verbalValue == "" || verbalValue > 100 || verbalValue < 0){
document.getElementById("verbalValue").style.border = '2px solid red';
document.getElementById("verbalValue").style.borderRadius = '5px';
}
else{
document.getElementById("verbalValue").style.border = 'none';
}
}
document.querySelector("button").addEventListener("click", () => verbalValidation());
function visualValidation() {
const visualValue = document.getElementById("visualValue").value;
if(visualValue == "" || visualValue > 100 || visualValue < 0){
document.getElementById("visualValue").style.border = '2px solid red';
document.getElementById("visualValue").style.borderRadius = '5px';
}
else{
document.getElementById("visualValue").style.border = 'none';
}
}
document.querySelector("button").addEventListener("click", () => visualValidation());
function average(){
const reactionValue = Number(document.getElementById("reactionValue").value);
const memoryValue = Number(document.getElementById("memoryValue").value);
const verbalValue = Number(document.getElementById("verbalValue").value);
const visualValue = Number(document.getElementById("visualValue").value);
if(reactionValue == "" || reactionValue > 100 || reactionValue < 0 || memoryValue == "" || memoryValue > 100 || memoryValue < 0 || verbalValue == "" || verbalValue > 100 || verbalValue < 0 || visualValue == "" || visualValue > 100 || visualValue < 0){
document.getElementById("score").innerHTML = "---";
}
else{
const total = Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4);
document.getElementById("score").innerHTML = total;
}
}
document.querySelector("button").addEventListener("click", () => average());
function rating() {
const reactionValue = Number(document.getElementById("reactionValue").value);
const memoryValue = Number(document.getElementById("memoryValue").value);
const verbalValue = Number(document.getElementById("verbalValue").value);
const visualValue = Number(document.getElementById("visualValue").value);
if(reactionValue == "" || reactionValue > 100 || reactionValue < 0 || memoryValue == "" || memoryValue > 100 || memoryValue < 0 || verbalValue == "" || verbalValue > 100 || verbalValue < 0 || visualValue == "" || visualValue > 100 || visualValue < 0){
document.getElementById("rating").innerHTML = "?";
}
else{
if (Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) <= 30){
document.getElementById("rating").innerHTML ="Next time will be better!";
}
else if (Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) > 30 && Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) <= 50){
document.getElementById("rating").innerHTML ="You can do better";
}
else if (Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) > 50 && Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) <= 70){
document.getElementById("rating").innerHTML ="Good";
}
else if (Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) > 70 && Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) <= 80){
document.getElementById("rating").innerHTML ="Great";
}
else if (Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) > 80){
document.getElementById("rating").innerHTML ="Perfect!";
}
}
}
document.querySelector("button").addEventListener("click", () => rating());
function rank() {
const reactionValue = Number(document.getElementById("reactionValue").value);
const memoryValue = Number(document.getElementById("memoryValue").value);
const verbalValue = Number(document.getElementById("verbalValue").value);
const visualValue = Number(document.getElementById("visualValue").value);
if(reactionValue == "" || reactionValue > 100 || reactionValue < 0 || memoryValue == "" || memoryValue > 100 || memoryValue < 0 || verbalValue == "" || verbalValue > 100 || verbalValue < 0 || visualValue == "" || visualValue > 100 || visualValue < 0){
document.getElementById("rank").innerHTML = "Please enter a value from 0 to 100, or press 'up' or 'down' arrow key on the input";
}
else{
if (Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) <= 30){
document.getElementById("rank").innerHTML ="You scored lower than 80% of the people who have taken these tests.";
}
else if (Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) > 30 && Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) <= 50){
document.getElementById("rank").innerHTML ="You scored lower than 60% of the people who have taken these tests.";
}
else if (Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) > 50 && Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) <= 70){
document.getElementById("rank").innerHTML ="You scored higher than 50% of the people who have taken these tests.";
}
else if (Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) > 70 && Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) <= 80){
document.getElementById("rank").innerHTML ="You scored higher than 65% of the people who have taken these tests.";
}
else if (Math.round((reactionValue + memoryValue + verbalValue + visualValue) / 4) > 80){
document.getElementById("rank").innerHTML ="You scored higher than 90% of the people who have taken these tests.";
}
}
}
document.querySelector("button").addEventListener("click", () => rank());