This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
forked from IseeJ/CosmosPersona
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Bob.js
189 lines (163 loc) · 5.54 KB
/
Bob.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
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
180
181
182
183
184
185
186
187
188
189
// Please do not use my code, pictures without permission! I'm happy to share this with you just please please let me know first!
// took me a year to finish this project and all I had then was python knowledge lol
const questions = [
{
question: "...?",
image: "images/B1.gif",
answers: {
C: {
text: "OMG BOB IT'S YOU!!!",
scores: { U: 0, C: +1 },
},
U: {
text: "Here we go again...Where am I?",
scores: { U: +1, C: 0 },
}
}
},
{
question: "'You! You're not suposed to be here!'",
image: "images/B2.gif",
answers: {
C: {
text: "This place is cool! Is this where you work? Is this how the quiz was created?!",
scores: { U: 0, C: +1 },
},
U: {
text: "I was told by the creator to find an easter egg, any ideas?",
scores: { U: +1, C: 0 },
}
}
},
{
question: "'An easter egg?! Wow, my boss really need to touch some grass with all these free time in her hands...'",
image: "images/B3.gif",
answers: {
U: {
text: "Hey...It's not a crime being a homebody.",
scores: { U: +1, C: 0 },
},
C: {
text: "lol I know right, she must be really bored..",
scores: { U: 0, C: +1 },
}
}
},
{
question: "'To be honest, I have no idea. Where do people normally keep eggs?'",
image: "images/B4.gif",
answers: {
C: {
text: "Maybe I should crack you open and see if you're hiding it in there?",
scores: { U: 0, C: +1 },
},
U: {
text: "You know you're a bad liar, right?",
scores: { U: +1, C: 0 },
}
}
},
{
question: "'Fine! Fine! She asked me to keep the secret! There... one of those boxes! Gosh, I don't get paid enough for this...'",
image: "images/B5.gif",
answers: {
U: {
text: "Open 'Trash with potential' box",
scores: { U: +1, C: 0 },
},
C: {
text: "Open 'I forgot I made these' box",
scores: { U: 0, C: +1 },
}
}
}
];
const resultOptions = {
"U": {
image: "BA.PNG",
},
"C": {
image: "BT.PNG"
}
};
let currentQuestion = 0;
// let userAnswers = {};
function displayQuestion() {
const quizElement = document.getElementById('quiz');
const question = questions[currentQuestion];
if (question) {
let html = `<p>${question.question}</p>`;
if (question.image) {
html += `<img src="${question.image}" alt="Question ${currentQuestion + 1}">`;
}
for (const option in question.answers) {
html += `<button class="large-rectangular" value="${option}" id="${option}">${question.answers[option].text}</button>`;
}
quizElement.innerHTML = html;
attachButtonClickHandlers();
} else {
}
}
document.getElementById('start-button').addEventListener('click', function() {
document.getElementById('start-page').style.display = 'none';
document.getElementById('quiz-page').style.display = 'block';
currentQuestion = 0;
userAnswers = {};
displayQuestion();
// userAnswers.userName = userName;
});
//click
function attachButtonClickHandlers() {
const choiceButtons = document.querySelectorAll('.large-rectangular');
choiceButtons.forEach((button) => {
button.addEventListener('click', handleAnswer);
});
}
//answers
function handleAnswer(event) {
const selectedOption = event.target;
const answerKey = selectedOption.value;
const question = questions[currentQuestion];
const answer = question.answers[answerKey];
for (const dimension in answer.scores) {
userAnswers[dimension] = (userAnswers[dimension] || 0) + answer.scores[dimension];
}
if (currentQuestion < questions.length - 1) {
currentQuestion++;
displayQuestion();
} else {
showResult();
}
}
// ...
function showResult() {
const resultElement = document.getElementById('result');
const resultTextContainer = document.querySelector('.result-text');
const resultImage = document.getElementById('result-image');
// Decide the result based on the scores
const result = (userAnswers['U'] || 0) > (userAnswers['C'] || 0) ? 'U' : 'C';
// Show result
const personalityData = resultOptions[result];
if (personalityData) {
resultTextContainer.innerHTML = `
<!-- You can add any result text here -->
`;
resultImage.src = "images/" + personalityData.image;
resultImage.alt = `${personalityData.image} Image`;
} else {
// Handle case if result is not found
}
// Hide the quiz, show the result, and show the restart button
document.getElementById('quiz').style.display = 'none';
resultElement.style.display = 'block'; // Show the result
}
//Function to restart the quiz
function restartQuiz() {
currentQuestion = 0;
userAnswers = {};
document.getElementById('result').style.display = 'none';
document.getElementById('quiz').style.display = 'block';
displayQuestion(); // Start the quiz from the beginning
}
document.getElementById('restart-button').addEventListener('click', restartQuiz);
displayQuestion();