ruslanmv commited on
Commit
6fc4c72
1 Parent(s): 6c474d7

First commit

Browse files
app.py CHANGED
@@ -10,7 +10,7 @@ app.config['SECRET_KEY'] = 'your_secret_key'
10
  socketio = SocketIO(app)
11
 
12
  questions = [
13
- {"question": "What is the capital of France?", "options": ["Paris", "London", "Berlin", "Rome"], "correct": "Paris"},
14
  {"question": "What is the largest planet?", "options": ["Earth", "Mars", "Jupiter", "Saturn"], "correct": "Jupiter"}
15
  ]
16
  initial_questions = questions.copy() # Keep a copy of the original questions to reset later
 
10
  socketio = SocketIO(app)
11
 
12
  questions = [
13
+ {"question": "What is the capital of France?", "options": ["Berlin", "Paris", "Rome", "Madrid"], "correct": "Paris"},
14
  {"question": "What is the largest planet?", "options": ["Earth", "Mars", "Jupiter", "Saturn"], "correct": "Jupiter"}
15
  ]
16
  initial_questions = questions.copy() # Keep a copy of the original questions to reset later
static/script.js CHANGED
@@ -19,14 +19,18 @@ socket.on('update_participants', (data) => {
19
  socket.on('new_question', (data) => {
20
  document.getElementById('waiting-message').style.display = 'none';
21
  document.getElementById('question-text').innerText = data.question;
22
- const options = data.options.map((opt) =>
23
- `<button onclick="submitAnswer('${opt}')" class="btn btn-secondary">${opt}</button>`
 
 
24
  ).join('');
25
  document.getElementById('options').innerHTML = options;
26
  });
27
 
28
- function submitAnswer(answer) {
29
- socket.emit('submit_answer', { answer: answer });
 
 
30
  }
31
 
32
  function checkAnswers() {
 
19
  socket.on('new_question', (data) => {
20
  document.getElementById('waiting-message').style.display = 'none';
21
  document.getElementById('question-text').innerText = data.question;
22
+ const letters = ['a', 'b', 'c', 'd'];
23
+ const options = data.options.map((opt, index) =>
24
+ `<input type="radio" id="${letters[index]}" name="answer" value="${opt}">
25
+ <label for="${letters[index]}">${letters[index]}) ${opt}</label><br>`
26
  ).join('');
27
  document.getElementById('options').innerHTML = options;
28
  });
29
 
30
+ function submitForm(event) {
31
+ event.preventDefault();
32
+ const answer = document.querySelector('input[name="answer"]:checked').value;
33
+ socket.emit('submit_answer', { answer });
34
  }
35
 
36
  function checkAnswers() {
static/style.css ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ background-color: #f4f4f4;
3
+ font-family: Arial, sans-serif;
4
+ }
5
+
6
+ .container {
7
+ max-width: 800px;
8
+ margin: 0 auto;
9
+ background-color: #fff;
10
+ padding: 20px;
11
+ border-radius: 8px;
12
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
13
+ }
14
+
15
+ h2, p {
16
+ font-size: 18px;
17
+ }
18
+
19
+ input[type="radio"] {
20
+ margin-right: 10px;
21
+ }
22
+
23
+ input[type="submit"] {
24
+ display: block;
25
+ margin-top: 20px;
26
+ }
templates/client.html CHANGED
@@ -5,6 +5,7 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Quiz Client</title>
7
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
 
8
  </head>
9
  <body>
10
  <div class="container">
@@ -14,8 +15,13 @@
14
  <div id="quiz-content" style="display: none;">
15
  <h3>Logged in as: <span id="logged-user"></span></h3>
16
  <h3 id="waiting-message" style="display: none;">Waiting for the Host...</h3>
17
- <h3 id="question-text"></h3>
18
- <div id="options"></div>
 
 
 
 
 
19
  <div id="results" class="mt-4"></div>
20
  </div>
21
  <div id="final-results" style="display: none;" class="mt-4">
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Quiz Client</title>
7
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
8
+ <link rel="stylesheet" href="/static/style.css">
9
  </head>
10
  <body>
11
  <div class="container">
 
15
  <div id="quiz-content" style="display: none;">
16
  <h3>Logged in as: <span id="logged-user"></span></h3>
17
  <h3 id="waiting-message" style="display: none;">Waiting for the Host...</h3>
18
+ <div id="question-section" class="mt-4">
19
+ <form id="quiz-form" onsubmit="submitForm(event)">
20
+ <p id="question-text"></p>
21
+ <div id="options"></div>
22
+ <input type="submit" value="Submit" class="btn btn-primary mt-2">
23
+ </form>
24
+ </div>
25
  <div id="results" class="mt-4"></div>
26
  </div>
27
  <div id="final-results" style="display: none;" class="mt-4">
templates/host.html CHANGED
@@ -5,6 +5,7 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Quiz Host</title>
7
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
 
8
  </head>
9
  <body>
10
  <div class="container">
@@ -14,8 +15,10 @@
14
  <button onclick="checkAnswers()" class="btn btn-primary mt-2">Check Answers</button>
15
  <button onclick="nextQuestion()" class="btn btn-secondary mt-2">Next Question</button>
16
  <button onclick="endQuiz()" id="end-quiz" class="btn btn-danger mt-2" disabled>End Quiz</button>
17
- <h3 id="question-text" class="mt-4"></h3>
18
- <div id="options" class="mt-2"></div>
 
 
19
  <div id="results" class="mt-4"></div>
20
  </div>
21
  <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.0/socket.io.js"></script>
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Quiz Host</title>
7
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
8
+ <link rel="stylesheet" href="/static/style.css">
9
  </head>
10
  <body>
11
  <div class="container">
 
15
  <button onclick="checkAnswers()" class="btn btn-primary mt-2">Check Answers</button>
16
  <button onclick="nextQuestion()" class="btn btn-secondary mt-2">Next Question</button>
17
  <button onclick="endQuiz()" id="end-quiz" class="btn btn-danger mt-2" disabled>End Quiz</button>
18
+ <div id="question-section" class="mt-4">
19
+ <p id="question-text"></p>
20
+ <div id="options"></div>
21
+ </div>
22
  <div id="results" class="mt-4"></div>
23
  </div>
24
  <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.0/socket.io.js"></script>