-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
179 lines (153 loc) · 7.02 KB
/
script.js
File metadata and controls
179 lines (153 loc) · 7.02 KB
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
171
172
173
174
175
176
177
178
179
const parts = new URL(window.location.href);
let nme = "";
let emailid = "";
let linkedin = "";
let facebook = "";
let twitter = "";
const pathToSrc = "pentagon-megathon/frontend/website/"
function readFields() {
inputs = document.querySelectorAll("input");
nme = inputs[0].value;
emailid = inputs[1].value;
linkedin = inputs[2].value;
facebook = inputs[3].value;
twitter = inputs[4].value;
}
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
function startTest() {
readFields();
userRef.set({
name: nme,
email: emailid,
linkedin,
facebook,
twitter
});
const absoluteRootURL = window.location.protocol + '//' + window.location.host + '/';
console.log(absoluteRootURL + pathToSrc + "question/question.html");
window.location = absoluteRootURL + pathToSrc + "question/question.html";
}
function initQuestions() {
setOptionHandlers();
getNextQuestion();
}
let askedQuestions = new Set();
const MAX_QNS = 6;
class Question {
constructor(number, statement, image, optionStatements, optionDeltas) {
this.number = number;
this.statement = statement;
this.image = image;
this.optionStatements = optionStatements;
this.optionDeltas = optionDeltas;
}
}
let ocean = [0, 0, 0, 0, 0];
let currentDeltas = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]];
const questions = [
new Question(0, "You are late for a meeting. When you leave your house in a hurry, you…", 0, ["A. Will be right on time - your keys and wallet are right where they are supposed to be.", "B. Need a few minutes to search for your keys and wallet - they never seem to be where you put them the night before!", "C. Always have a plan B just in case things don't go well", "D. Ask help from friends as much as possible"], [[0, 20, 0, 0, 0], [0, -20, 0, 0, 0], [15, 0, 0, 0, 0], [0, 0, 20, 0, 0]]),
new Question(1, "Since you are finishing your work early, your boss is assigning you more work. What would you do in such situation?", 0, ["A. Raise your concerns with your boss", "B. Keep doing more work to prove yourself", "C. Agree to do work but put less effort", "D. Throw a tantrum in office"], [[0, 0, 10, -20, 0], [10, 0, -5, 10, 0], [0, 0, -20, 0, 0], [0, -10, 0, 0, 20]]),
new Question(2, "What do you identify first in this picture:", 0, ["A. Crocodile", "B. A Boat a kid and a father", "C. Red Circle", "D. Random Figures"], [[0, 5, 0, 15, 0], [0, 0, 0, 0, 20], [20, 15, 0, 0, 0], [-20, 0, -15, 0, 0]]),
new Question(3, "Which two puzzles will you will you choose first, (harder ones have more weightage)?", 0, ["A. Molecule 3-D puzzle and Metal Brainteasers", "B. Shooting star puzzle and Interlocking Bicycle", "C. Crystal Skull and Labyrinth maze", "D. Rubik's cube and I don't know what others are"], [[0, 20, 0, 0, 0], [20, 0, 0, 0, 0], [0, 0, 0, 0, -20], [0, 0, 0, 20, 0]]),
new Question(4, "What time do you wake up on average for a morning shift?", 0, ["A. 4 AM to 5:30 AM", "B. 6 AM to 7:30 AM", "C. past 8 AM", "D. 7-8 hrs after I sleep, can be anytime"], [[0, 30, 0, 0, 0], [-15, 0, 0, 0, 10], [0, -25, 0, 0, 0], [20, -35, 0, 0, -20]]),
new Question(5, "How often do you participate in debates?", 0, ["A. Frequently, I like to hear other's opinions and discuss pros and cons", "B. Frequently, most people disagree with me and have to get into debates to get stuff done", "C. Rarely, I just don't find myself in such situations", "D. Rarely, its just a waste of time and most debaters are passive agressive anyways"], [[30, 0, 15, 0, 20], [0, 0, 10, -20, 0], [0, 0, -10, 30, 0], [-20, 0, -20, 0, 0]])
];
function setQuestionNumber() {
document.querySelector(".question_number").innerHTML = askedQuestions.size.toString() + ".";
}
function setOptions(opt) {
let options = document.querySelectorAll(".option");
for (let i = 0; i < options.length; i++) {
options[i].innerHTML = opt[i];
}
}
const PARAMS = 5;
function setOptionHandlers() {
let options = document.querySelectorAll(".option");
for (let i = 0; i < options.length; i++) {
options[i].addEventListener("click", function(event) {
for (let j = 0; j < PARAMS; j++) {
ocean[j] += currentDeltas[i][j];
}
getNextQuestion();
});
}
}
function setQuestion(question_text) {
document.querySelector(".question_text").innerHTML = question_text;
}
const names = ["Openness", "Conscientiousness", "Extroversion", "Agreeableness", "Neuroticism"];
function showResults() {
document.querySelector(".question_img_div").remove();
document.querySelector(".question_container").remove();
document.querySelector(".option_container").remove();
// let mn = ocean[0];
// for (let i = 0; i < 5; i++) {
// if (ocean[i] < mn) mn = ocean[i];
// }
// if (mn < 0) {
// for (let i = 0; i < 5; i++) {
// ocean[i] -= mn;
// }
// }
let container = document.querySelector(".container");
let display_text = document.createElement("div");
display_text.className = ".question_container";
display_text.innerHTML = "Submitted, a detailed report will be emailed to you.";
display_text.style.fontFamily = "Roboto Bold";
display_text.style.fontSize = "3rem";
container.appendChild(display_text);
let oceanContainer = document.createElement("div");
oceanContainer.style.display = "flex";
oceanContainer.style.justifyContent = "space-evenly";
oceanContainer.style.alignItems = "center";
oceanContainer.style.width = "80%";
for (let i = 0; i < 5; i++) {
let chld = document.createElement("div");
chld.innerHTML += names[i];
chld.innerHTML += ": ";
chld.innerHTML += ocean[i].toString();
chld.style.fontSize = "2rem";
oceanContainer.appendChild(chld);
}
container.appendChild(oceanContainer);
oceanRef.set({
o: ocean[0],
c: ocean[1],
e: ocean[2],
a: ocean[3],
n: ocean[4]
});
}
function getNextQuestion() {
if (askedQuestions.size == MAX_QNS) {
console.log("too many questions");
showResults();
return;
}
let imgDiv = document.querySelector(".question_img_div");
if (imgDiv.childElementCount > 0) {
let chld = document.querySelector(".q_img");
imgDiv.removeChild(chld);
}
rng = getRandomInt(MAX_QNS);
while (askedQuestions.has(rng)) {
rng = getRandomInt(MAX_QNS);
}
currentDeltas = questions[rng].optionDeltas;
askedQuestions.add(rng);
setQuestionNumber();
setOptions(questions[rng].optionStatements);
setQuestion(questions[rng].statement);
if (rng == 2 || rng == 3) {
let imgDiv = document.querySelector(".question_img_div");
let qimg = document.createElement("img");
if (rng == 2) qimg.src = "../images/puzzle1.png";
else qimg.src = "../images/puzzle2.png";
qimg.className = "q_img";
qimg.style.width = "50%";
imgDiv.appendChild(qimg);
}
}