This project is a competitive two-player trivia game built using HTML, CSS, and JavaScript. Players input their names, choose a category, and answer trivia questions fetched from The Trivia API. The game keeps track of the scores based on the correctness of the answers and declares a winner at the end.
- Player Setup: Two players enter their names to start the game.
- Category Selection: Players choose a category from a list, and the game fetches 6 trivia questions (2 easy, 2 medium, 2 hard) from the selected category.
- Turn-Based Gameplay: Players take turns answering questions. Scores are awarded based on the difficulty level of the question.
- Score Calculation:
- Easy question: 10 points
- Medium question: 15 points
- Hard question: 20 points
- Post-Question Options: After all questions in a category are answered, players can either select another category or end the game.
- Game End and Results: The game ends when players choose to end it or all categories are exhausted. The player with the higher score is declared the winner.
- HTML: For structuring the web pages.
- CSS: For styling the game interface.
- JavaScript: For handling game logic, API interactions, and user interaction.
- Clone the repository:
git clone https://github.com/yourusername/two-player-trivia-game.git
- Navigate to the project directory:
cd two-player-trivia-game
- Open the project in a web browser:
- You can open the
index.html
file directly in your browser or use a local server like Live Server in VSCode for live reloading.
- You can open the
- Enter Player Names: Both players should enter their names and click "Start Game."
- Select a Category: Choose a category from the dropdown list.
- Answer Questions: Players take turns answering questions. Player 1 answers the first easy question, Player 2 answers the second easy question, and so on.
- Score Calculation: Points are awarded based on the difficulty of the question answered correctly.
- Post-Question Options: After all questions in a category are answered, players can either select a new category or end the game.
- End Game and Results: The game ends when players choose to end it or all categories are exhausted. The player with the higher score wins.
- The Trivia API: This project uses The Trivia API to fetch trivia questions. More details about the API can be found here.
- Ensure that the selected category is not reused.
- The game currently fetches questions in separate requests for each difficulty, which could cause delays.
If you'd like to contribute to the project, feel free to fork the repository and submit a pull request. Suggestions for new features and bug reports are also welcome!
This project is licensed under the MIT License. See the LICENSE file for details.
- Thanks to The Trivia API for providing a reliable source of trivia questions.
- Thanks to the HVA Mini Hackathon for providing the opportunity to build this project.