For this weekend weekend project we will create a quiz app. Please implement features from the set below.
You are welcome to build the application using just React or use Redux as well. See Redux getting started guide at the end.
We will be using Open Trivia Database database to obtain questions. You can load random questions, one at a time from https://opentdb.com/api.php?amount=1&type=multiple. The API returns both true/false questions as well as multiple choice. We will use multiple choice by default.
The question received from the API will have a structure similar to below and provide a correct answer as well as several incorrect answers.
{
"response_code":0,
"results":[
{
"category":"Entertainment: Video Games",
"type":"multiple",
"difficulty":"medium",
"question":"Which of these characters was almost added into Super Smash Bros. Melee, but not included as the game was too far in development?",
"correct_answer":"Solid Snake",
"incorrect_answers":[
"Pit",
"Meta Knight",
"R.O.B."
]
}
]
}See https://opentdb.com/api_config.php for more info on the API.
-
Fork and clone this repo. Run
npm installto get all dependencies. -
Load the first question automatically at the beginning using
componentDidMountand display it to the user. Alongside buttons for the answers. -
If the user clicks a correct answer, notify the user and increment the score by 1. On an incorrect answer, notify the user and reset the score to 0. You are welcome to use an alternative scoring system if you prefer.
-
If the user answers the question correctly load the next question.
-
Each correct answer should increment the score. It's up to you how you want to score answers. You could apply a different score for different difficulty grades. After each correct answer display the next question
-
Make the app responsive and look good at all screen sizes.
-
Show the user a 'happy' animated gif on a correct answer and a 'sad' gif on incorrect answer.
-
Allow user to select question category
-
Allow user to select difficulty level
-
Add some unit tests
-
Implement a scoring system that gives higher scores for more difficult questions
-
Create a high score table. When a user finishes the game, for example answers a question incorrectly, allow them to enter their name and add it along with score to a high score table.
-
Display statistics about player performance such as total questions played, average score, most popular category, category with highest percentage of correct etc.
-
Allow both
true/falseand multiple choice questions to be played. -
Implement an extension of your choice.
- Document your solution in a README.md
- Make frequent commits
- Create a pull request at the end
If you are using planning to use Redux, use the steps below to help you get started.
-
Create a React
Questioncomponent that will display a question to the user. It will receive 2 props from container.questionobject - current question from store that will come frommapStateToPropsfetchQuestionfunction - which will be used to trigger the fetching of a newquestionusingmapDispatchToProps
-
The React
Questioncomponent should implement acomponentDidMountmethod that we will use to trigger the initial question load. Add a console.log at the beginning ofcomponentDidMountto outputStep 1: calling fetchQuestion. -
Create a Redux
QuestionContainerthat will talk to Redux on behalf ofQuestioncomponent. -
In
QuestionContainerimplement amapDispatchToPropsmethod which we will use to receive thefetchQuestioncall from theQuestionComponent. Add a console.log inside the method which implementsfetchQuestioninmapDispatchToPropssayingStep 2: getting action creator -
Create an asynchronous action creator in
actions/index.jscalledfetchQuestionFromAPI. It should return a function which will receivedispatch. Inside the function, implement afetchto the API to receive the question. Add a console.log just inside the action creator sayingStep 3: calling fetch. Add another console.log inside the secondthenof thefetchand console.log the returned data. -
Import the
fetchQuestionFromAPIaction creator from previous step intoQuestionContainercall it usingdispatchfrommapDispatchToProps. -
Implement a new action, which will receive data returned by the fetch call and return a new action object which should have an action type of
RECEIVE_QUESTIONand aquestionproperty which should be set the received question object. Add a console.log withStep 4 - creating RECEIVE_QUESTION question objectto the action creator. -
Implement a reducer called
questionto handle theRECEIVE_QUESTIONaction and set it in state. Add a console.log withStep 5 - setting question in state. You may want to initialise the default value of state to be an empty object. Don't forget to implement the default case. -
Add the
questionreducer toreducers/index.jsand remove theplaceholderreducer as we no longer need it. -
Implement
mapStateToPropsinQuestionContainerwhich should take thequestionfrom reducer state and pass it as aquestionprop to theQuestioncomponent. Add a console.log tomapStateToPropswhich outputsStep 6 - calling mapStateToProps in QuestionContainer. -
Add some conditional rendering that checks if the question object received as
propsis not just an empty object to ensure it can be rendered without errors.
