write me a javascript program that drives a single-page web application that tests users…
- User
write me a javascript program that drives a single-page web application that tests users knowledge with multiple-choice questions
Assistant
Below is a basic example of a single-page web application written in JavaScript, HTML, and CSS that tests a user's knowledge with multiple-choice questions. This application will:
- Display a question and its multiple-choice options.
- Allow the user to select an answer.
- Check if the selected answer is correct.
- Display the result (correct or incorrect) and an explanation (if provided).
- Proceed to the next question upon user confirmation.
- End the quiz when all questions have been answered, displaying a final score.
Note: For simplicity, questions, options, correct answers, and explanations are predefined within the JavaScript code. In a real-world application, you might want to fetch these from a database or API.
HTML (index.html)
html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Knowledge Quiz</title> <link rel="stylesheet" href="style.css"> </head> <body> <div id="quiz-container"> <h2 id="question"></h2> <ul id="options"></ul> <p id="result"></p> <p id="explanation"></p> <button id="submit-btn">Submit</button> <button id="next-btn" style="display:none;">Next Question</button> <div id="final-score" style="display:none;"></div> </div> <script src="script.js"></script> </body> </html>CSS (style.css)
cssbody { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f0f0f0; } #quiz-container { background: white; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0,0,0,0.1); } #options { list-style: none; padding: 0; } #options li { margin-bottom: 10px; } #options li input[type="radio"] { margin-right: 10px; } #result, #explanation { margin-top: 20px; } #submit-btn, #next-btn { margin-top: 20px; padding: 10px; cursor: pointer; } #final-score { font-size: 24px; font-weight: bold; margin-top: 20px; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.