Fausto Busuito commited on
Commit
44f0b86
1 Parent(s): eda232c

Application changes

Browse files
Files changed (2) hide show
  1. app/static/script.js +27 -29
  2. app/static/style.css +8 -3
app/static/script.js CHANGED
@@ -34,45 +34,43 @@ function displayQuestion() {
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) {
77
  const currentAnswers = userAnswers[currentIndex];
78
  if (currentAnswers.includes(optionIndex)) {
 
34
  const optionsDiv = document.getElementById('options');
35
  optionsDiv.innerHTML = '';
36
 
37
+ const form = document.createElement('form');
38
+ form.id = 'question-options';
39
+
40
  question.options.forEach((option, i) => {
41
+ const input = document.createElement('input');
42
+ input.type = isMultipleChoice ? 'checkbox' : 'radio';
43
+ input.name = 'answer';
44
+ input.value = i;
45
+ input.checked = userAnswers[currentIndex].includes(i);
46
+
47
+ input.addEventListener('change', () => {
48
+ if (isMultipleChoice) {
49
+ // Add or remove the answer for multiple choice
50
+ if (input.checked) {
 
51
  userAnswers[currentIndex].push(i);
52
  } else {
53
  userAnswers[currentIndex] = userAnswers[currentIndex].filter(j => j !== i);
54
  }
55
+ } else {
56
+ // Set only one answer for single choice
 
 
 
 
 
 
 
 
 
 
 
 
57
  userAnswers[currentIndex] = [i];
58
+ }
59
+ });
60
+
61
+ const label = document.createElement('label');
62
+ label.appendChild(input);
63
+ label.appendChild(document.createTextNode(option));
64
+ label.style.display = 'block';
65
+ label.style.marginBottom = '10px';
66
 
67
+ form.appendChild(label);
 
68
  });
69
+
70
+ optionsDiv.appendChild(form);
71
  }
72
 
73
+
74
  function selectAnswer(optionIndex) {
75
  const currentAnswers = userAnswers[currentIndex];
76
  if (currentAnswers.includes(optionIndex)) {
app/static/style.css CHANGED
@@ -17,7 +17,12 @@ body {
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
  }
 
17
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
18
  }
19
 
20
+ input[type="radio"], input[type="checkbox"] {
21
+ margin-right: 10px;
22
+ cursor: pointer;
23
+ }
24
+
25
+ label {
26
+ font-size: 16px;
27
+ cursor: pointer;
28
  }