-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (45 loc) · 1.66 KB
/
index.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
const answers = document.querySelectorAll(".answer-block");
const questions = document.querySelectorAll(".question");
const arrows = document.querySelectorAll("#arrowIcon");
let currentQuestionId;
let currentAnswer;
let currentQuestion;
let currentArrow;
let numberOfOpenQuestions = 0;
let openAswersList = [];
let openQuestionsList = [];
let transformedArrows = [];
answers.forEach((answer, index) => {
answer.style.display = "none";
answer.setAttribute('id', index);
});
questions.forEach((question, index) => {
question.setAttribute("id", index);
question.addEventListener("click", showAnswer);
});
function showAnswer(question) {
currentQuestionId = question.target.id;
currentAnswer = answers[currentQuestionId];
currentQuestion = questions[currentQuestionId];
currentArrow = arrows[currentQuestionId];
if (currentAnswer.style.display === "none") {
currentArrow.style.transform = "rotate(180deg)";
currentQuestion.style.color = "var(--tx-pr-blue)";
currentQuestion.style.fontWeight = "700";
currentAnswer.style.display = "initial";
openAswersList.push(currentAnswer);
openQuestionsList.push(currentQuestion);
transformedArrows.push(currentArrow);
numberOfOpenQuestions += 1;
}
if (numberOfOpenQuestions === 2) {
transformedArrows[0].removeAttribute('style');
openAswersList[0].removeAttribute('style');
openQuestionsList[0].removeAttribute('style');
openAswersList[0].style.display = "none";
numberOfOpenQuestions -= 1;
openAswersList.shift(openAswersList[0]);
openQuestionsList.shift(openQuestionsList[0]);
transformedArrows.shift(transformedArrows[0]);
}
}