Fausto Busuito
commited on
Commit
·
eda232c
1
Parent(s):
57819f8
Application changes
Browse files- app/static/script.js +31 -25
- app/static/style.css +5 -0
app/static/script.js
CHANGED
@@ -34,37 +34,43 @@ function displayQuestion() {
|
|
34 |
const optionsDiv = document.getElementById('options');
|
35 |
optionsDiv.innerHTML = '';
|
36 |
|
37 |
-
const ul = document.createElement('ul');
|
38 |
-
ul.style.listStyleType = 'disc';
|
39 |
-
|
40 |
question.options.forEach((option, i) => {
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
if (currentAnswers.includes(i)) {
|
53 |
-
userAnswers[currentIndex] = currentAnswers.filter(j => j !== i);
|
54 |
-
} else {
|
55 |
userAnswers[currentIndex].push(i);
|
|
|
|
|
56 |
}
|
57 |
-
}
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
userAnswers[currentIndex] = [i];
|
60 |
-
|
61 |
-
|
62 |
-
});
|
63 |
|
64 |
-
|
|
|
65 |
});
|
66 |
-
|
67 |
-
optionsDiv.appendChild(ul);
|
68 |
}
|
69 |
|
70 |
function selectAnswer(optionIndex) {
|
|
|
34 |
const optionsDiv = document.getElementById('options');
|
35 |
optionsDiv.innerHTML = '';
|
36 |
|
|
|
|
|
|
|
37 |
question.options.forEach((option, i) => {
|
38 |
+
if (isMultipleChoice) {
|
39 |
+
// Checkbox for multiple choice
|
40 |
+
const label = document.createElement('label');
|
41 |
+
label.style.display = 'block';
|
42 |
+
label.style.marginBottom = '10px';
|
43 |
+
|
44 |
+
const checkbox = document.createElement('input');
|
45 |
+
checkbox.type = 'checkbox';
|
46 |
+
checkbox.checked = userAnswers[currentIndex].includes(i);
|
47 |
+
checkbox.addEventListener('change', () => {
|
48 |
+
if (checkbox.checked) {
|
|
|
|
|
|
|
49 |
userAnswers[currentIndex].push(i);
|
50 |
+
} else {
|
51 |
+
userAnswers[currentIndex] = userAnswers[currentIndex].filter(j => j !== i);
|
52 |
}
|
53 |
+
});
|
54 |
+
|
55 |
+
label.appendChild(checkbox);
|
56 |
+
label.appendChild(document.createTextNode(` ${option}`));
|
57 |
+
optionsDiv.appendChild(label);
|
58 |
+
} else {
|
59 |
+
// Pushbutton for single choice
|
60 |
+
const button = document.createElement('button');
|
61 |
+
button.innerText = option;
|
62 |
+
button.style.display = 'block';
|
63 |
+
button.style.marginBottom = '10px';
|
64 |
+
button.className = userAnswers[currentIndex][0] === i ? 'selected' : '';
|
65 |
+
|
66 |
+
button.addEventListener('click', () => {
|
67 |
userAnswers[currentIndex] = [i];
|
68 |
+
displayQuestion();
|
69 |
+
});
|
|
|
70 |
|
71 |
+
optionsDiv.appendChild(button);
|
72 |
+
}
|
73 |
});
|
|
|
|
|
74 |
}
|
75 |
|
76 |
function selectAnswer(optionIndex) {
|
app/static/style.css
CHANGED
@@ -16,3 +16,8 @@ body {
|
|
16 |
border-radius: 8px;
|
17 |
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
18 |
}
|
|
|
|
|
|
|
|
|
|
|
|
16 |
border-radius: 8px;
|
17 |
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
18 |
}
|
19 |
+
|
20 |
+
button.selected {
|
21 |
+
background-color: #4caf50;
|
22 |
+
color: white;
|
23 |
+
}
|