Create a Trivia Game using ReactJS
Quizzical is a Trivia game implemented in ReactJS by Harmeet Matharoo and Habib ur rehman Bhatti. While creating this project I learned about Event Listeners in React, React State, Conditional Rendering in React, React Hooks(useEffect), etc. A player is given 5 random questions with 4 choices each. Trivia questions are retrieved from Open Trivia Database API. A participant can validate their answers and can play as many times as they want. Have Fun π. After creating the project, it was deployed to GitHub Pages π¦ Feel free to reach me onTwitter πΎ
- Open Trivia Database API
- ReactJS
- create-react-app
- Figma Design Template
- Event Listeners in React
- React State
- Conditional Rendering in React
- React Hooks(useEffect)
- github-pages
### Clone the repository using GitHub CLI
gh repo clone hmjatt/Quizzical### Go to the quizzical folder
cd quizzical### Install Dependencies
npm install### Starts the Development Server(App will open in a new window)
npm start- Initialize the project using
npx create-react-app quizzicalwhich will create a complete React App pre-configured and pre-installed with all the dependencies. - Import
Work Sansfont from google fonts and apply it to theAppcomponent.
- Create a
componentsfolder for custom components inside thesrcdirectory. - Create a
stylesfolder inside thesrcdirectory and move.cssfiles inside it.
- Delete unnecessary files.
- Create a
testsfolder inside thesrcdirectory and move.test.jsfiles inside it. - Delete unnecessary code.
-
Create an
Appcomponent and basic JSX elements for it. -
Add appropriate
classNames to elements in theAppcomponent. -
Import
Appcomponent insideindex.js. -
Add styles to
bodyinsideindex.css. -
Style
Appcomponent by editingApp.css. And also addblobelements toAppcomponent
- Create a
Quizcomponent, basic JSX elements for it and import it inAppcomponent.
- Create
Footercomponent and basic JSX elements for it. - Import
Footercomponent insideAppcomponent. - Style
Footercomponent.
- When
Start Quizbutton is clicked, conditionally renderQuizcomponent.
- Add elements to
Quizcomponent. - Style elements in
Quizcomponent. - Make it responsive.
-
Change code inside
Quizcomponent, so that multiple options can be selected for a playthrough but only one option to be selected per question. Can be easily done by convertingbuttonstoradio inputsand applying some styles.
- Add link to
Habib ur rehman Bhatti's GitHub in footer as he finished points#11and#12. Thanks friend π and looking forward to colaborate with you in future projects, learned a lot while doing this project.
- Fetch data from
Trivia API. - Replace psuedo questions with the fetched questions.
- Replace psuedo answers with the fetched answers.
- Add loading animation while fetching data.
- Randomize the order of answers.
-
Add logic to check if answer is correct or not.
-
Save the score in a variable.
-
Display the score in when the
Submitbutton is clicked. -
Replace the
Submitbutton withPlay Againbutton when theSubmitbutton is clicked. -
Change background color if the answer is correct or wrong.
-
Render the score component.
-
Add logic to reset the score when the
Play Againbutton is clicked.
- Change Absolute units to Relative.
- Make App responsive for mobile by adding
media query. π
- Delete unnecessary files from directory and format code with
Prettier. - Test for Responsiveness and make changes if need be.
- Add links to
Live Previewand screenshots.
- Use Official Documentation(link) to push the project to GitHub Pages πππ
- Allow players to select category of trivia questions.
- Allow players to select difficulty of trivia questions.
- Divide Quiz Component into smaller components.
- Use Styled Components and CSS Modules to tidy up CSS.
-
The Odin Project
-
Figma Design
-
Scrimba
-
React Official Documentation
-
Trivia API
βAll parts should go together without forcing. You must remember that the parts you are reassembling were disassembled by you. Therefore, if you canβt get them together again, there must be a reason. By all means, do not use a hammer."
β IBM Manual, 1925
πβ π




