Make a website of the game "20 questions"
- User
Make a website of the game "20 questions"
Assistant
Sure, here's a simple HTML template for a "20 Questions" game website. This template includes basic HTML, CSS, and JavaScript to create a functional game.
20 Questions Game Website
index.html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>20 Questions Game</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="container"> <h1>20 Questions Game</h1> <div id="game"> <p id="question-number">Question 1</p> <p id="question">Is it an animal?</p> <button onclick="answer('yes')">Yes</button> <button onclick="answer('no')">No</button> <p id="result" class="hidden">Thinking...</p> </div> </div> <script src="script.js"></script> </body> </html>styles.cssbody { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f0f0f0; } .container { text-align: center; background: white; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } button { margin: 10px; padding: 10px 20px; font-size: 16px; cursor: pointer; } .hidden { display: none; }script.jsconst questions = [ "Is it an animal?", "Is it a living thing?", "Is it bigger than a breadbox?", "Can it fly?", "Does it live in water?", "Is it a mammal?", "Is it a household pet?", "Is it a wild animal?", "Is it a fruit?", "Is it a vegetable?", "Is it a piece of furniture?", "Is it electronic?", "Is it something you wear?", "Is it a vehicle?", "Is it a musical instrument?", "Is it a book?", "Is it a game?", "Is it a tool?", "Is it edible?", "Is it man-made?" ]; let currentQuestion = 0; let thinking = false; document.getElementById('question').innerText = questions[currentQuestion]; function answer(answer) { if (thinking) return; thinking = true; document.getElementById('result').classList.remove('hidden'); document.getElementById('result').innerText = "Thinking..."; setTimeout(() => { currentQuestion++; if (currentQuestion < questions.length) { document.getElementById('question-number').innerText = `Question ${currentQuestion + 1}`; document.getElementById('question').innerText = questions[currentQuestion]; } else { document.getElementById('question').innerText = "I give up! What is it?"; } document.getElementById('result').classList.add('hidden'); thinking = false; }, 1000); // Simulate thinking time }Explanation
-
HTML:
- The
index.htmlfile sets up the basic structure of the webpage, including the game container, question display, and answer buttons.
- The
-
CSS:
- The
styles.cssfile adds basic styling to make the game look presentable. It centers the content, styles the buttons, and hides the result text initially.
- The
-
JavaScript:
- The
script.jsfile contains the logic for the game. It defines an array of questions and handles the user’s answers. When a user clicks a button, it simulates "thinking" for a second before moving to the next question.
- The
You can expand this basic template by adding more questions, improving the styling, or even integrating a backend to save game states or track statistics.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.