This quiz web app is built using React JS. It can allow the user to select the criteria for their quiz from a list of options. The user can then proceed to answer the questions in the quiz and their performance will be tracked and shown in the scoreboard
Here's a description of the changes made to the provided code:
Timer Feature:
We added a timer feature to each question in the quiz.
useState and useEffect hooks are used to manage the timer.
timer state variable keeps track of the remaining time in seconds, initially set to 30 seconds.
timerInterval state variable is used to store the interval ID for the timer.
startTimer function initializes the timer and starts counting down from 30 seconds.
stopTimer function clears the timer interval when the question changes or when the quiz finishes.
In the useEffect, we start the timer when a new question is displayed and stop it when the quiz is finished.
The remaining time is displayed in the UI using <p>Time Left: {timer} seconds</p>.
Progress Bar Feature:
We added a progress bar to indicate the progress of the quiz visually.
CSS classes progress-bar and progress are used to style the progress bar. Make sure to add appropriate CSS styles for these classes.
The width of the progress bar is determined based on the current question's index (next) and the total number of questions (len).
The progress bar is a visual representation of how far the user has progressed in the quiz.
These enhancements improve the user experience of the quiz by adding a time limit per question and a visual indicator of progress. Users can see how much time is remaining for each question and how far they have progressed in the quiz.
Here's a description of the changes made to the provided code:
Timer Feature:
useState
anduseEffect
hooks are used to manage the timer.timer
state variable keeps track of the remaining time in seconds, initially set to 30 seconds.timerInterval
state variable is used to store the interval ID for the timer.startTimer
function initializes the timer and starts counting down from 30 seconds.stopTimer
function clears the timer interval when the question changes or when the quiz finishes.useEffect
, we start the timer when a new question is displayed and stop it when the quiz is finished.<p>Time Left: {timer} seconds</p>
.Progress Bar Feature:
progress-bar
andprogress
are used to style the progress bar. Make sure to add appropriate CSS styles for these classes.next
) and the total number of questions (len
).These enhancements improve the user experience of the quiz by adding a time limit per question and a visual indicator of progress. Users can see how much time is remaining for each question and how far they have progressed in the quiz.