-
-
Notifications
You must be signed in to change notification settings - Fork 934
a Simple and Fun Quiz App #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // vendors | ||
| import { Fragment, useState } from "react"; | ||
|
|
||
| //css | ||
| import "./FrontScreen.scss"; | ||
|
|
||
| const EndScreen = ({ quizSummary, redirectHome }) => { | ||
| const { correctAnswers, cheatedAnswers, wrongAnswers, result } = quizSummary; | ||
| const [currentQuestion, setCurrentQuestion] = useState({}); | ||
|
|
||
| const ShowCurrentQuestionDetails = ({ currentQuestion }) => { | ||
| if (!Object.keys(currentQuestion).length) return false; | ||
| return ( | ||
| <div | ||
| className={`display-question ${ | ||
| currentQuestion.correct ? "correct" : "incorrect" | ||
| }`} | ||
| > | ||
| <div className='question-number'>Question: {currentQuestion?.qNo}</div> | ||
| <li | ||
| dangerouslySetInnerHTML={{ | ||
| __html: `${currentQuestion?.question}`, | ||
| }} | ||
| /> | ||
| <span | ||
| dangerouslySetInnerHTML={{ | ||
| __html: `<br/><b>Ans</b>: ${currentQuestion?.correct_answer}<br/>`, | ||
koustov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }} | ||
| /> | ||
| <span | ||
| dangerouslySetInnerHTML={{ | ||
| __html: `<b>Your Answer</b>: ${currentQuestion?.your_answer}`, | ||
| }} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <Fragment> | ||
| <div className='fun-quiz-main'> | ||
| <div className='main-child'> | ||
| <h1>Quiz Summary</h1> | ||
| {!cheatedAnswers ? ( | ||
| <h2 className='congrats'>Congratulations!</h2> | ||
| ) : ( | ||
| <h2 className='cheated'>You Cheated!</h2> | ||
| )} | ||
| <div className='quiz-summary'> | ||
| <div> | ||
| <h4> | ||
| <span>{correctAnswers}</span> | ||
| <span>Correct Answers</span> | ||
| </h4> | ||
| {!!cheatedAnswers && ( | ||
| <h4 className='cheated'>({cheatedAnswers} cheated)</h4> | ||
| )} | ||
| </div> | ||
| <div> | ||
| <span>{wrongAnswers}</span> | ||
| <span>Wrong Answers</span> | ||
| </div> | ||
| </div> | ||
| <div className='front-footer'> | ||
| <button onClick={redirectHome}>Home</button> | ||
| </div> | ||
| <div className='circle-area'> | ||
| {result.map((item, index) => { | ||
| return ( | ||
| <div | ||
| key={`${item.question + index}`} | ||
| className={ | ||
| item.correct ? "circle-correct" : "circle-incorrect" | ||
| } | ||
| onClick={() => | ||
| setCurrentQuestion({ ...item, qNo: index + 1 }) | ||
| } | ||
| > | ||
| {index + 1} | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
| <ShowCurrentQuestionDetails currentQuestion={currentQuestion} /> | ||
| </div> | ||
| </div> | ||
| </Fragment> | ||
| ); | ||
| }; | ||
|
|
||
| export default EndScreen; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { useState } from "react"; | ||
|
|
||
| // css | ||
| import "./FrontScreen.scss"; | ||
| import options from './options.json' | ||
|
|
||
| const CATEGORY_SELECTION = "CATEGORY_SELECTION"; | ||
| const RULES_DISPLAY = "RULES_DISPLAY"; | ||
|
|
||
| const QuizSelectionScreen = ({ getSelectedCategory }) => { | ||
| const [selectedOption, setSelectedOption] = useState(""); | ||
| const [view, setView] = useState(CATEGORY_SELECTION); | ||
|
|
||
| const letMeInHandler = () => { | ||
| if (!selectedOption) return; | ||
| setView(RULES_DISPLAY); | ||
| }; | ||
|
|
||
| const RulesComponent = () => { | ||
| return ( | ||
| <> | ||
| <p>1. There will be 20 Unique Questions.</p> | ||
| <p>2. Every Question will have 4 multiple choices to chooose.</p> | ||
| <p> | ||
| 3. Among 4 options only one option will be correct answer of the | ||
| Question. | ||
| </p> | ||
| <p> | ||
| 4. Answer selection isn't mandatory. You can skip choosing any answer | ||
| and it will be counted as incorrect answer. | ||
| </p> | ||
| <p> | ||
| 5. After answer confirmation you cannot go back to previous question | ||
| or donot refresh the page otherwise you will lose you progress. | ||
| </p> | ||
| <p> | ||
| 6. You will be given 30 seconds to answer each question and timeup is | ||
| considered as an incorrect answer and next question will be displayed. | ||
| </p> | ||
| <p> | ||
| 7. After selecting an option you can click on selected option to unselect it. | ||
| </p> | ||
| <p>8. You can use cheats to cheat the answer.</p> | ||
| <div className='front-footer'> | ||
| <button onClick={() => getSelectedCategory(selectedOption)}> | ||
| Yes, Lets Start! | ||
| </button> | ||
| </div> | ||
| <div> | ||
| <button className='back' onClick={(e) => setView(CATEGORY_SELECTION)}> | ||
| « Back | ||
| </button> | ||
| </div> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| const CategorySelector = () => { | ||
| return ( | ||
| <> | ||
| <p> | ||
| The Quiz app requires to have a specefic category in order to start | ||
| with. Select one of the below options in which you have expertise in. | ||
| </p> | ||
| <div className='selectable-options'> | ||
| {options.map((option) => { | ||
| return ( | ||
| <div | ||
| key={option.id} | ||
| onClick={(e) => setSelectedOption(option.id)} | ||
| className={`single-selection ${ | ||
| selectedOption === option.id && "active-selected" | ||
| }`} | ||
| > | ||
| {option.name} | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
| <div className='front-footer'> | ||
| <button onClick={letMeInHandler}>Let me in</button> | ||
| </div> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| const renderView = view === CATEGORY_SELECTION; | ||
|
|
||
| return ( | ||
| <div className='fun-quiz-main'> | ||
| <div className='main-child'> | ||
| <h1>{!renderView ? "Quiz Rules" : "Quiz App"}</h1> | ||
| {renderView && <CategorySelector />} | ||
| {!renderView && <RulesComponent />} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default QuizSelectionScreen; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.