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

Application changes

Browse files
Files changed (2) hide show
  1. app/static/script.js +37 -7
  2. app/templates/index.html +1 -1
app/static/script.js CHANGED
@@ -29,15 +29,42 @@ function startQuiz() {
29
  function displayQuestion() {
30
  const question = questions[currentIndex];
31
  document.getElementById('question').innerText = question.question;
 
 
32
  const optionsDiv = document.getElementById('options');
33
  optionsDiv.innerHTML = '';
 
 
 
 
34
  question.options.forEach((option, i) => {
35
- const btn = document.createElement('button');
36
- btn.innerText = option;
37
- btn.className = userAnswers[currentIndex].includes(i) ? 'selected' : '';
38
- btn.addEventListener('click', () => selectAnswer(i));
39
- optionsDiv.appendChild(btn);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  });
 
 
41
  }
42
 
43
  function selectAnswer(optionIndex) {
@@ -74,5 +101,8 @@ document.getElementById('end-session').addEventListener('click', async () => {
74
 
75
  function updateTimer() {
76
  const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
77
- document.getElementById('timer').innerText = `Time: ${elapsedTime}s`;
78
- }
 
 
 
 
29
  function displayQuestion() {
30
  const question = questions[currentIndex];
31
  document.getElementById('question').innerText = question.question;
32
+
33
+ const isMultipleChoice = /Select TWO|Choose two/i.test(question.question);
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) {
 
101
 
102
  function updateTimer() {
103
  const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
104
+ const hours = String(Math.floor(elapsedTime / 3600)).padStart(2, '0');
105
+ const minutes = String(Math.floor((elapsedTime % 3600) / 60)).padStart(2, '0');
106
+ const seconds = String(elapsedTime % 60).padStart(2, '0');
107
+ document.getElementById('timer').innerText = `Time: ${hours}:${minutes}:${seconds}`;
108
+ }
app/templates/index.html CHANGED
@@ -22,7 +22,7 @@
22
  <div id="quiz-container" style="display: none;">
23
  <div id="question-container">
24
  <p id="timer">Time: 0s</p>
25
- <h2 id="question"></h2>
26
  <div id="options"></div>
27
  <div id="navigation">
28
  <button id="prev">Previous</button>
 
22
  <div id="quiz-container" style="display: none;">
23
  <div id="question-container">
24
  <p id="timer">Time: 0s</p>
25
+ <h2 id="question" style="font-weight: normal;"></h2>
26
  <div id="options"></div>
27
  <div id="navigation">
28
  <button id="prev">Previous</button>