An awesome quiz about sports displayed with multiple choice questions. Supported by the api: Open Trivia DB
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
This React app connects itself to the Open Trivia DB API and allows users to play a quiz game where, for each question, they can choose 1 out of the 4 answers displayed. In the end, the app will show the score, the correct answers and the ones the user failed.
This section should list any major frameworks that you built your project using. Leave any add-ons/plugins for the acknowledgements section. Here are a few examples.
- React
- create-react-app
- Open Trivia DB API
- Sass
- Flexbox
- CSS Modules
- Promises and .then method - How do they work. When the user clicks the button to play a new game, the data has to be fecthed from the API again to retrieve a new set of questions and answers. Because there are functions that run faster than others, and the way it works is asynchronously, needed to place the function call, which was running before the API fetch, inside the .then method, in order to avoid displaying the older set of questions and answers.
const fetchApi = () => {
fetch("https://opentdb.com/api.php?amount=5&category=21&type=multiple")
.then((response) => response.json())
.then((data) => {
setQuestionsAndAnswers(
(...)
);
// to play again, I want to clean the old answers only after the new set of questions / answers is displayed
setAreAllAnswersChecked(false);
});
};
- Object destructuring in array methods
const score = questionsAndAnswers.filter(
({ userAnswer, correctAnswer }) => userAnswer === correctAnswer
).length;
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
You need to install the following elements:
- npm
npm install npm@latest -g
- yarn
npm install yarn -g
- Get a free JSON API at https://opentdb.com/api_config.php. Use of this API does not require an API Key.
- Clone the repo
git clone git@github.com:Francisco-Webdeveloper/sports-quiz.git
- Install NPM packages
yarn install
This project was bootstrapped with Create React App.
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
Note: this is a one-way operation. Once you eject
, you can’t go back!
If you aren’t satisfied with the build tool and configuration choices, you can eject
at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject
will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use eject
. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Your Name - @FranciscoLX81 - francisco.santos.lx81@gmail.com
Project Link: https://github.com/Francisco-Webdeveloper/sports-quiz