Fausto Busuito commited on
Commit
eda232c
·
1 Parent(s): 57819f8

Application changes

Browse files
Files changed (2) hide show
  1. app/static/script.js +31 -25
  2. 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
- const li = document.createElement('li');
42
- li.style.cursor = 'pointer';
43
- li.style.marginBottom = '10px';
44
- li.className = userAnswers[currentIndex].includes(i) ? 'selected' : '';
45
-
46
- li.innerText = option;
47
-
48
- li.addEventListener('click', () => {
49
- if (isMultipleChoice) {
50
- // Allow multiple selections
51
- const currentAnswers = userAnswers[currentIndex];
52
- if (currentAnswers.includes(i)) {
53
- userAnswers[currentIndex] = currentAnswers.filter(j => j !== i);
54
- } else {
55
  userAnswers[currentIndex].push(i);
 
 
56
  }
57
- } else {
58
- // Allow only one selection
 
 
 
 
 
 
 
 
 
 
 
 
59
  userAnswers[currentIndex] = [i];
60
- }
61
- displayQuestion();
62
- });
63
 
64
- ul.appendChild(li);
 
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
+ }