Skip to content

Quiz about sports displayed with multiple choice questions. Supported by the api: Open Trivia DB

License

Notifications You must be signed in to change notification settings

Francisco-Webdeveloper/sports-quiz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


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

Table of Contents

About The Project

Screenshot 2022-05-18 at 11 06 43

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.

Built With

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.

What I learned

  • 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;

Getting Started

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.

Prerequisites

You need to install the following elements:

  • npm
npm install npm@latest -g
  • yarn
npm install yarn -g

Installation

  1. Get a free JSON API at https://opentdb.com/api_config.php. Use of this API does not require an API Key.
  2. Clone the repo
git clone git@github.com:Francisco-Webdeveloper/sports-quiz.git
  1. Install NPM packages
yarn install

Usage

This project was bootstrapped with Create React App.

Available Scripts

In the project directory, you can run:

yarn start

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.

yarn test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

yarn build

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.

yarn eject

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.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Your Name - @FranciscoLX81 - francisco.santos.lx81@gmail.com

Project Link: https://github.com/Francisco-Webdeveloper/sports-quiz

Acknowledgements

About

Quiz about sports displayed with multiple choice questions. Supported by the api: Open Trivia DB

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published