Podcast Lookup

Build a Quiz Application with React.js – Complete Beginner-Friendly Project Tutorial

ReactJS Developers Podcast

  • December 3, 2026
  • 55 min
  • Episode 15
Episode page
About this episodeIn this episode, we explore how to build an interactive Quiz Application using React.js from scratch.Building a quiz application is an…
In this episode, we explore how to build an interactive Quiz Application using React.js from scratch.Building a quiz application is an excellent way to practise React fundamentals while developing a real-world project. You'll learn how to create interactive questions, display multiple-choice answers, track user selections, and calculate quiz scores.We'll combine React components, state management, event handling, and conditional rendering to create an engaging quiz experience.Whether you're learning React for the first time or looking for practical portfolio projects, this tutorial will help you turn your React knowledge into a functional application.What You'll Learn
  • Understanding the structure of a React quiz application.

  • Setting up a React project.

  • Creating reusable question and answer components.

  • Displaying multiple-choice questions.

  • Managing quiz state with the useState Hook.

  • Handling answer selections and user interactions.

  • Implementing next and previous question navigation.

  • Tracking user scores and correct answers.

  • Using conditional rendering.

  • Displaying quiz results and final scores.

  • Creating a restart quiz functionality.

  • Improving the user interface and experience.

Who Should Watch?
  • Beginners learning React.js.

  • JavaScript and frontend developers.

  • Software engineering students.

  • Developers building portfolio projects.

  • Anyone interested in practical React application development.

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

Build a Quiz Application with React.js – Complete Beginner-Friendly Project Tutorial

00:00—
  1. Speaker 1

    Again, a lovely basic project and the name of this project is Quiz App. We are going to make a quiz app, although it is a very basic application, it is very basic for you to see. But you will get to learn a lot of things in it, a lot of concepts will be cleared. And all the things we have read in phase 2 are based on that, I have not discussed anything extra here. All the things in phase 2, all those things will be cleared in this together and some extra concepts. How to manage index by yourself. Because you don't have to use the whole map to render. There is a map too. And how to manage index by yourself. How to apply logic. How to manage timer. and how to work on the basis of timer. All the things are mixed up here, so the use effect will be cleared properly, the state will be cleared properly, and if I talk about props and components, then it is definitely clear. So this is our last project of phase 2, these are two basic projects. I have told you about the previous project, you can see that. There are some things that I have told you, so I am not explaining it again in this project. Because I had told you in that. Although I will explain a little bit, but not that much. So if you go to the playlist in the sequence, it will be very fun. So what is this project? So the project is our simple quiz app. First of all, your time must be running here. So you just saw the time, the time was over, so your result was showing here and the score was 0. So, on the basis of time, you can give as much time as you want. On time left, you should be able to see the score by removing the question. How much score you have done. If you have not done any score, then definitely your score will be 0. And if you have done any score, like there are only 3 questions here. You can add as many questions as you want in JSON. We have made it with JSON, so you will get the idea of JSON. A lot of things.

  2. Speaker 2

    Okay.

  3. Speaker 1

    So, which language runs in a web browser? So, here the simplest answer is JavaScript. What does CSS stand for? So, the answer is Cascading Style Seed. But let's say I tick the wrong option. I couldn't even tick it, I didn't see the time. So I reload it again, I'll do it quickly and show you. You increase the time, java script, I select some wrong options here, cascading simple sheet. And when it was launched, so here I tick the right option, 1995. So my two were correct, so your score is 2. Okay. Although it could have been shown like this, out of 3. Okay, so show it like this. and you can do some extra tasks like you can show the question here that there are so many questions like there are 3 questions and in 3 this is the first question in 3 you can see the second question in 3 you can see the third question in 3 the current index which I have told in this project you can manage that and show all that too so this is your task rest I have told you the whole project and told it in a very proper way I have told it by writing it and also by making a diagram so it will be fun but you can see the last lecture also and follow it in sequence then it will be more fun Okay, so let's start the project. Come on, quickly. So as always, first of all, you have to make a new folder by right-clicking here. So that you can save your code properly. Our folder is already made here. We are doing all the work here. We are learning and making a project. So definitely I will do it in this as well. I will do open with VS Code by right-clicking. So simply open a folder in VS Code. Now do whatever you want. Okay. And here I close it. This is our VS Code. Let's fullscreen it a little bit. And here First of all, we will open the terminal. All right. And what do we need here? We have to install VEET and Tailwind. So this time we come directly to the Tailwind site. And we will quickly install both Tailwind and VEET. This is our VEET. So let's quickly copy and paste it. And now we don't have to do anything. Simply give the name of the project here. It will be installed. Alright. and should have given cd because you have to go inside to install other things. Now this experimental feature I am telling you from the last 2-3 lectures that it is new and experimental is going on. So for now, do not do it. As soon as there will be some performance improvement or some features will come, then I will tell you. So do not do it for now. And you can do this. It is saying that should I install npm and start it? It is asking should I start it? If you want to start, then do it. I don't want to do it now because I am going to install Tailwind. We will come to the project folder. Now we are in the project folder. Now we have to install Tailwind. I have told you in a proper way, so there should not be any problem in this. So here we will copy it, go to this and paste it. Do paste here and here in this way, press it next to react in this way. Okay, so this is ours. As he is saying, I am doing the same, I am not doing anything else. You have to copy from here and here in the main CSS, app.css, which is main css? index.css, right? So, in this, in the starting, you have to paste it in the top. I am not removing css, right? I have left app.css also, main dot, sorry, index.css also I have left, because here some styles are already made, so it is good. Only I will give button tag, here button style will be done, I don't need to do anything else. So, some styles are already made, so let it be, our hard work will be saved. Okay, main purpose is to understand our logic here, not css. So this is done. Let's clear it. And I believe we can use tailwind too. So let's run npm run dev. Let's minimize it too. Before minimizing, let's open it in browser. So this is done. Now we can minimize it. After that, come to app.jsx. Clean this raita. Remove it from here. Remove this too. and in main.jsx this time remove strict mode because later we will remove it so remove it now so here you know strict mode I removed it so that it doesn't check again and again and I don't see the same output in the console twice there is a little bit of confusion ok so in app.jsx first of all let's check whether our tailwind is properly configured or not hello and here we will give class name bg red we are getting suggestions 500 Suggestions are not coming. Has our Tailwind not been configured properly? No, BGColorRed has been configured. Tailwind has been configured. Give me suggestions. Give me suggestions. Give me suggestions. How will it work like this? And yes, I forgot to zoom in this time too. Here I have zoomed in. Now you must be seeing clearly even if you are watching on mobile. So what suggestions are we getting? Yes, we are getting now. tailwind is also working and we have installed it properly so what we have to make in this we have to make some things which may look a bit complex but I will tell you in a very easy way although there are small things to make if you paste on chatgpt, gemini or any AI it will give you code and you can use it easily But you don't have to do this. In the beginning, you have to focus on learning. You don't have to use AI right now. Rest, when you come to the company or you are making client projects or you are freelancing yourself, then you have to use AI a lot. And then you will feel that to use AI, it is very important to have a strong logic. If your logic is not strong, then you will not be able to use AI properly. So using AI is a good thing. Don't be afraid of AI. We have to use AI, but for now we have to make all the logic stronger by ourselves because we are learning React. After learning, you have to take the help of AI definitely. You have to make everything with the help of AI. But in the starting, definitely you have to do everything by yourself. Intermediate projects, advanced projects, whatever I have told you, you have to try to make it by yourself. By looking at it, but by yourself. If you are doing it with AI, then by looking at it, but by yourself. At least you have to code and understand. Alright, so now let's move ahead. And what we had to do, there were 2-3 components, our timer, a question one, a result one. So right now I am remembering so much, so what I will do here, I will make a folder called components here. And I will make a new file here, timer.jsx. This is one component of ours, one will be our questions.jsx. So, what is JX? It is JS. It is JSX. Where did you get this JX from? JSX. Okay. Then, here will come one more. Tell me quickly, what is result.jsx? Okay. And this is done. So let's start making the timer quickly. And in app.jsx, let's import the timer quickly. The timer is also imported and it has come here. And let's remove these two. Now they don't need it. Let's make the timer first. Let's make a small, cute timer. After that, we will make the question one. After that, we will make the result one.

  4. Speaker 2

    Okay.

  5. Speaker 1

    Let's make it in chunks. Once you take the full burden, it will be a very difficult project. But it is still a very easy project. So what we have to do here is that we have to write all the logic here. So what we have to do in timer, basically we don't have to make a clock. Timer can be of 30 seconds, 60 seconds, then one by one it will come back, like 30 is 29, then 28, then 27, like this. And after 0, it should stop there. So first we have to decrement. 10 to 9, 9 to 8, 8 to 7, whatever happens we have to decrement. First we have to do this work. So for this we should get this much idea till now. All of you who are watching me now. So you should get this much idea that at least one state will be made here. Where we will save time. 30 seconds are left, 28 seconds are left. 15 seconds are left, for that we have to make a state here. So const left time comma set left time is equal to use state and in starting we give 5 seconds. I have given less so that it is over quickly. Otherwise if we give 30 seconds time, then we have to wait 30 seconds. So now I have given 5, you give 60 seconds. Give 1 minute, 2 minutes, 3 minutes, as much as you have to give. Now we have to show left time here. What can we show? We can definitely show. Here is left time. And here we write time left just for clarity. And here we put an emoji. I have a lot of clocks, so you can see which clocks are in your window, so you put one clock here, it looks good, nothing else, it looks good, this clock will not be running your time, don't think like this, this clock is running the time, okay, here once I remember that basically in the first semester, one sir gave a question that here we have to print, we have to print the pattern, so there is a response from the back that we will print f, In the first line, printf 1 star, in the second line, printf 2 star, in the third line, printf 3 star. And something like this. So, this also happens. That's why I told you that this clock is not working for you. Here we will write our own logic. This is just here. I have given it like this for show off. There is nothing else. Okay. So, now a lot of people are abusing here. Have we understood so much noob? Oh, man, I was a noob too. That's why I am talking about myself. So, why do you take it on your own heart? Hmm. We have to reduce the time left of 5. We have to do 5 to 4, 4 to 3, 3 to 2, 2 to 1. How will we do it? We have to set an interval. We have to set an interval in the starting. As soon as the component is loaded, listen carefully what I am trying to say. As soon as the timer component is loaded, we have to set an interval of 1 second and keep on decrementing. So as soon as the component is loaded, we have to do something about it. So what do we do? Use effects definitely. In the lecture on use effect, I told you in the lecture on hook, we will use the use effect here. It is taking a function, along with it it is taking a dependency array. So the dependency is not on anyone right now, so we will leave the dependency array empty and we will make the function fat arrow function here. You can also make a normal function, no problem. So what we have to do here, we have to make a set interval here. And to make a set interval, we need an interval of 1 second here. We will reduce the time in each second. Okay. In 1 second, we will do 5 to 4, then we will do 4 to 3 after 1 second. So in this way, our second will be reduced. Alright, so how to reduce? So set, set, set. What have I written? Set left time, right? Okay. Set left time. In the beginning, beginners will think that set left time to left time. Will do minus 1 and that's it, it will do our work. You must be thinking that yes, definitely this work should be done. But I am saying that it will not work. Think about why it will not work. I think it will stop at 4 after 5 because it will be working at the same time. Basically, it will be updating, it will be minus, but it will be happening at 5. So it will stop at 4. Why will it stop? Tell me quickly. Why will it stop here? Why won't it work? Left time minus 1 is fine. On each second, set left time will keep doing left time minus 1. What is the problem in this? What is the problem? See, let's come here. Let's reload. 5, 4 and stop. As I said, it stopped at 5, 4. Why did this happen? Tell me quickly. I had told you definitely. I had also told you about use state. UseEffect was also mentioned. Leave the effect, this is the question of the state. If the same question is asked to you, then what will you do? Definitely you will get stuck. Okay, the logic should definitely be clear. In the state, I told you that whenever you have a problem with re-rendering, that it does not re-render immediately, it is scheduled here. So whenever you are handling an event, like you are doing set interval, then set left time will be here. In which? In this left time. Set left time, left time will be minus 1, left time will be 5, 5 will be minus 1, so 4 will be there. So 4 will be there, but it will not be re-rendered and updated immediately. So it will be working on the old left time, on 5. If you want to understand it with full clarity, then go and watch the state lecture. For now, it will not work like this. Here we have to use functional update if we want to work with current state. It is not working with current state. Left time is working on 5 only. 4 is not doing minus 1 in 4, it is doing minus 1 on 5 only. So here we have to work with the current state. To work with the current state, we use the functional update here. And in functional update, we make a function in this way. You must be knowing this much. So here in this way, I will call it previous time and previous minus 1. This much you have come now. After seeing so much lecture, if there is not so much, then what did you read? So previous minus 1. So, time will decrease one by one. 5 to 4, 4 to 3, 3 to 2, 2 to 1, and then 1 to 0, and then from 0 to minus. This is the problem. Now, how will you fix this problem that it doesn't go to minus? It doesn't go to minus. So, here definitely you have to stop the interval. How will you stop? How will you stop? So here I will save its ID as let interval ID is equal to First of all, we will do the cleanup work here. Why is the cleanup work necessary? I believe I have told you in a project or lecture. I will not be able to give you an example of mount and unmount right now. However, we will see it in the life cycle lecture in more detail. So for now, clean up here. Clear interval and here Interval ID is here. Alright. Whenever a component is unmounted, it will clear the interval. If you want to write for now, write it. If you don't want to write, it will work fine now. There is no issue. We will understand it in more depth later. How to clean the garbage etc. So we have saved the interval ID here. Now we have cleared the interval through the ID of this interval. But when it will be unmounted. But we have to clear the interval as it is 0, 5, 4, 4, 3, 3, 2, 2, 1. And as it is 0, we have to clear the interval there. It should not go before that. So it is going here. So how will we do this? So to do this, now again many people will think that here in the starting. Here in the starting of useEffect, without thinking, you are doing this work. This is the problem. What will you do here? Here you will do something like this. ClearInterval, if, if, you will do something like this. If leftTime is less than or equal to 0, if it is less than or equal to 0, So here you will do something like this, clear interval, interval ID, clear interval and then interval ID. And here we will do return, that's it. Now you will feel that this work should be done, but it will not work. Tell me what is the reason behind this. To make a project is very easy, you can make small projects very quickly. But to understand this concept, because all these things are asked of you. All these things are asked to you. If you know all these things, you will definitely be able to handle big projects without making bug projects. So tell me here, it is still not stopping at 5 to 0. Why is this happening? So just now I told you about this functional update funda. It does not re-render immediately. You have done this work in the use effect, so it will continue to work. It will work on the old state, it will not work on the current state. So here you are not getting the current state. You will only get the old pipe. So here I will show you CLG left time.

  6. Speaker 2

    Ok.

  7. Speaker 1

    So here you have to type control shift once and see that you have a pipe. Use effect is not running again and again here when the dependency changes. Ok. We have not given anything to the dependency. So keep this in mind and also this old state too. If I show you here. I can give you an example here as well. If you do left time minus one, then here if you want to see the left time by doing CLG, then reload, then see this pipe, pipe, pipe, this pipe is remaining, it is not changing, it is working on the old state, if we want to work on the current state, then here we will have to use the same syntax, the functional update one, in this way. Ok, so I will remove this, it will not work this way, you know. So how will it work? So definitely we will have to do something inside the functional update. So what I am doing here, here I am this. But here you have to put the condition. If previous state is less than or equal to 0. So here you have to do clear interval. And here you have to give interval id. Now it will work. Now it will work definitely. Let's reload. 5, 4, 3, 2, 1, 0, and minus 1. And here, why did minus 1 come? It had to stop at 0, why did minus 1 come? Now let's see why it went to minus 1. It was supposed to stop at 0, but it went to minus 1. Actually, we haven't returned here. Look carefully, we have missed the return here. So whenever this interval is stopped here, it stopped at 0. It was a clear interval, but again it returned the previous minus 1. So how much will be 0 and minus 1? Minus 1. So add end you will get minus 1 and after that it will end here. So here you have to return also so that whenever there is a clear interval, that is, if it comes inside this block, then it will return from here, not on this. And if you just return, that means you are returning an empty value, then nothing will be seen here. See 5, 4, 3, 2, 1, 0 and then it will be completely empty here. So that's why you have to return 0 here, this is better. So now I am reloading 5 4 3 2 1 Interval is also clear and now it will remain 0. Because we have done return 0 here. So you understood so much logic, when you have to do outside, when you have to do inside. See the lecture on state, if you are having a lot of confusion here, then definitely state and use effect if you are not clear. Especially state, here the state was the whole funda that when the state changes, when it reflects, when it is re-rendered, how is the schedule, all those things. Definitely go and see the lecture on state. I have tried to explain it to you. If it still didn't come, then you haven't seen it. I have explained it in more detail. If all these things are clear, then our timer has been made. If you give 60 seconds in the timer, then it will stop at zero. But we didn't have to show it this way. We had to show it in the proper format. Because we had to show it in the format, we had to show one use effect in the format. So, we need to create one more useEffect. Now, we need to give Dependency. Why we need to give Dependency? Dependency is left time. Now, why we need to give Dependency left time? Because we need to change the format of left time. If left time is 10, then we need to change the format to 0 minutes 10 seconds. If left time is changing, then it is 9 seconds. So 0 minutes 9 seconds. In this way, whenever left time is changing, then we have to show it in the proper format. So for now, I will console here. And here I write hello. So see, as the left time is changing, hello is being printed again and again. As the left time is changing. So here you must be seeing the left time. Now to do the proper format here, I will use the string template literal. In this way, This is left time. This is second time. This is second time. If you want to change second time in minutes then this is simple logic. I don't think you need to tell this. If something is in second, like 60 seconds, we have to change it in minutes. I don't know why it is lagging. If it is 60 seconds, we have to change it in minutes, so we will divide it by 60, it will be 1 minute. So if we divide it by 60, it will change in seconds. And suppose if it is 61, so if we divide 61 by 60, it will be 1 point something, but we have to take 1, 1 minute. The remainder will be your second. So 1 minute and 1 second. So remainder will be second. And rest whatever will be left after dividing 60 will be minute. So here we will work like this. Divide 60. This will be minute. This much minute. And remainder will be second. So this much minute and this much second. So now let's see. Let's come to the browser and reload. This much minutes and this much seconds. And this is coming in a lot of points. So we have to fix this definitely. Here we have to take mat.floor. Why are we taking floor? We could have taken seal too. But one will be more than seal. Like I just told you here. 61 divided by 60. So here 1 point something or something will come. So if I will do seal. Then the integer value above it will come. That means 2. We don't need 2. We need the lower integer value 1. Which is 1 minute. So we will do floor here. Now I don't know why I am explaining so much. If you want, I will explain. Math.floor. Okay. And here also definitely we. Math. Oh, did we divide in both? Here we had to do modulo. So here definitely remainder will be left. So there is no need to do math.floor. Okay. So now let's come here and see what is coming. So 0 minute 5 seconds, 0 minute 4 seconds, 0 minute 3 seconds, 0 minute 2 seconds, 0 minute 1 second. But we don't have to show it like this. We have to format it a little bit more. Here we have to put colon instead of minute. And remove this second etc. Okay. So we will see something like this. Something like this. Reload. Like this. But we don't have to show it like this. Here if it is 0 then it should be 00. If it is 1 then it should be 01. It should be 0 in front. If it is single digit then it should be 0 in front. And if there are 2 digits like 10, 20, 25, then it's fine. But if there are 1, 2, 3, 4, 5, then there should be a zero in front of it. This happens in time, you see carefully. As you can see here, it's 3.21 am, so there is a zero in front of it, 0, 3. This question is very important. You can ask this question in your interview. I was asked this question once in my personal interview. How to do this? If a value is coming from the database and we have to keep it as 3 digits. If you can't complete it, then you have to add zero. How to do this? For this, you have a method called padStart. PadStart only works on string. So, you have to convert it to string. I will convert this whole to. toString. After converting it to string, we get a method called padStart. and here I am taking these two things. First of all, the length of the string. How much will it be? It will be 2, it will be 3. Basically, you can understand how many characters there will be. 2 length means definitely 2 characters. So how much will it be? So I need 2. And if 2 is not possible, then what do you have to put next? What do you have to put in the starting? So you have to put 0, you have to put A. Like if I put A here, then look carefully what will come here. A0. A0. Okay? So here I give 0. Okay? Then after that here, again I will convert it to 2 string and then here dot pad start and here 2 and 0 something like this now see how much proper format you will see see 0 5 4 3 2 1 0 ok now if you want to put 1 minute here also if you want to put 1 minute also like if you do 60 here then see 1 minute 59 seconds, 58, 57, 56 and it will keep going like this. So, we don't keep this much otherwise we won't be able to make the next project. So, we keep 5 seconds and according to me the timer is complete here. Now, we have to display it here and show it too. So, definitely we have to save it in a state. Okay, because it is changing again and again. So, it is such a state that it reflects in the UI when it changes again and again. So, definitely we have to save it in a state. So, let's make a variable. formatted time is equal to and this variable we will make a state here const display name display time comma set display time is equal to is equal to use state and here here we will leave something empty and here we will set display time Set display time, formatted time. So whenever the left time changes, like 10 to 9, whenever the left time changes, it will be formatted and it will come in formatted time. And we will show the display time here. So now if you look carefully here, I will reload it. So see 4, 3, 2, 1. And if you increase the timer here, like I do it here. Where did it go? I will set 60 or 70, now you see carefully 1 minute 10 seconds, 70 means 1 minute 10 seconds definitely, 8, 7, 6, 5, 4, 3, 2, 1, do it fast, then 59, 58, and it will stop at 0 definitely, if you want to check whether it stops at 0 or not, then set the timer to 4, 4, 3, 2, 1, 0, then left and we have to show some results. So how we will show all that, how we will do conditional rendering, we will discuss all those things definitely. But before that, let's take a little break. This timer has been made. So this was our left time logic. format logic. And it was so good to show here. The rest was a game of logic. So, I am selecting all these projects so that you can clear many things at the same time. For example, you will get a proper idea of use effect, state, conditional rendering, components, etc. Okay. So, take a little break. After that, close the timer. app.jsx and then come to the questions. Our timer is complete. I will drink some water. Till then, you also drink some water. Freshen up. And if this is not enough, then try to do it yourself. Now let's make the questions component. I have added the questions.json file so that you don't waste your time. I have already taken all the data in this. There is an array of objects and json is nothing different. I have also told you about this in the javascript and in the react series. Even if it is not coming by chance, it will be understood by looking at it. And if it is coming, then it is better. So here we don't need to give any variable. In the JSON file, we can only write in the format of an array object. So we have made an array here so that it is easy for us. This is an array of object. Each object is coming here. You already know that I put a string in the array. So we have put each object here. Now there are three things in each object. Look carefully. There are questions, options, and answers. And wait a minute, let me check that it is working properly. Yes, it is fine. So what I was saying, I was saying that in every object you have questions, options, and answers. Look carefully here, question, options, answer. Question, options, answer. Answer is given so that we can match whether the right option is ticked or not. And you know questions and options. Okay. So let's make the question component quickly. We have already done it here. So rafce will be our question and here questions all right So we have got the questions component here, we will quickly import the questions array here, so how will we do it? It is a simple way to import questions, just like we import the normal component, the same way to do the json is the same way. You can give the name of the variable here, from dot slash questions dot json is here, we will be using the same questions here, I will console you and show you here, CLG questions. and it is not being used, remove it ok, so let's quickly come here and reload, CTRL-SHIFT-I and here you are getting the array of objects we have three questions in the array, we will add more so here it will definitely come in the same way alright, now what to do here so first of all we have to show the question ok, let's show a question in H1 or H2 so how will the question look, quickly tell ok, one more thing Do we map it? Think about it. If there is an array, will we map it? Many of you might have thought that we will map it. We don't have to map it. Think carefully that you have to show only one question at a time. You don't have to show all the questions. You have to show only one question at a time. You have to get the second question when the option is right or wrong. Then you have to get the second question when the option is right or wrong. Only one question at a time. at a time we need one question so we have to access on the basis of index 0th index, 1st index, 2nd index so here we make a state const current index whenever index changes our question will change automatically current index comma set index is equal to useState By default we put 0 in the index. So if you want to see the questions of the current index, that means in the questions array, if you want to see the zero index, then you will get the first object on the zero index. If you put the index first, then you will get the second object. So you can work like this here. So how will you do it? So first of all, of current index. This will be an object. Now in object, you have a question. So you know how to access object. We can access the object with dot notation. So dot question is the key. So our question is coming here. Now we have to show the options. So we have to map the options because we have to show all the options at once. So here we have the option to map. Definitely javascript curly braces open close. And here we will write our javascript questions of current index. OK dot dot what what is that option stick dot options dot is to map it. So we definitely know here how to use the map. Here you will have one item coming. One item will be coming. Basically, you can say that an option will be coming. Option and here we will show the option and this is not a question. Oh man, I don't know what is happening. Question stick so here return what we have to return? we have to show the option as a button ok? style will also be automatically done so button and here for now it will be empty here we have to show the option like this so here it is all the options the first question is done all the options are here now what we have to show here? nothing else we have to show only question and option so this is the question and option is here wrap it in a div and style it a little here in this way class name flex ok and flex direction not flex direction we can directly do flex column here and we will give gap of 3 and see how it looks so it is looking like this and it is looking like this because it is zoomed so this much is enough ok and on top of this we will give margin of top of 5 So something like this is coming and above the heading, let's give it in the heading itself. Let's give the class name in the heading itself. From margin-top 8 and from margin-bottom 4. So it looks like this right now. Time left is coming up and here your question is coming and here the option is coming. Now we have shown the option properly, it is working on the basis of index. Now how will the index be managed? How will the index be managed? So index We have to manage the index by ourselves. We are not doing the map, so we will get the index there. So we have to manage the index by ourselves. And this key error is coming, so you know how to solve it. Here you will get the key, here pass the key. So what will you pass in the key? Something unique should happen, so if you pass the whole option here, then there is no problem. So the error will go. Alright. So, very good. However, if there is an ID or something in it, then you can pass it by looking at it. You can also give an index in it. Here in the loop, you get an index, you know. So, what to do next? Our question has come, our option has come. Now, when you click on the option, understand carefully, when you click on the option, There should be two things. First of all, the question should change and the next question should come. The next question should come. That means our current index should increase. There should be an increment in the index. Alright. Second, there should be an increment in the score if it is correct. And if it is not correct, then your score will remain 0 to 0. Okay. So we have to do something like this. So first we will make the score variable here. Sorry. Const score comma set score is equal to useState And the score will remain zero in the starting. Okay. So we have to do two things here. Definitely. So let's do one thing. Let's make a function. Const handle option click. Handle option click. Okay. Here is our handle option click. And here we will pass it in on click. But we have to do it this way to get the parameters. So that we can call it. So click on the handle option and pass the option here. Alright. So here you will get one option. Selected option. And here we will do CLG selected option. So let's see if we have an option. I believe we should have an option. What we have done here is that we write the name of the direct tip when we have to call. You must have seen this many times. So we are passing the reference so that it gets called when it clicks. But we have to send the parameter here, so if we do it this way, then it will be called automatically. We don't have to call it automatically, we have to call it when it clicks. So that's why we pass the reference here. So now we can't pass the reference here, so we will make a new function here. Pass the reference and make this whole function. We will call it inside this. And here we will pass the option. So whatever option will be selected, you will get it here. Let's reload. I clicked on C. So C is coming. I clicked on Python. so Python is coming. I clicked on JavaScript, so JavaScript is coming. I clicked on Java, so Java is coming. So if the option is correct, basically if it matches, then we have to open the score. That means selected option, if selected option matches our questions' current index, CurrentIndex.questions.currentIndex.answer If it matches, both are equal. If the answer on the currentIndex is equal to the selected option. That means you have ticked the correct answer. If you have ticked the correct answer, then we will set the score. previous plus 1 previous plus 1 ok set score we have done previous plus 1 so here one score has increased ok if you want you can see the score here let's remove this let's make the score CLG so let's reload what is the correct answer in this if I click on C then the score is not plus if I click on JavaScript then our score is plus 1 ok alright what else we have to do and we have to increase the question further that means we have to increment in index also we have to do increment in index so this is done with set current index so what we can do in set current index We have to do plus one, we can do previous, now we will do plus one, although some more logic will be applied here. Now I will tell you why. If we reload, then see, if I click on the wrong one, then it will go ahead. Then I click on the next object, that means it came to the next question, but now if I click, then there were only three questions. Now if the index goes ahead, then it will not get a question, if it does not get a question, then we will get an error. See this. cannot read properties of undefined. There were only three questions, right? There were only three questions. So, how can we go ahead of three questions? So, here we have to put some condition that we don't have to go ahead of it. Okay? And if that is the last question, then we have to finish it, finish it and show the result. So, let's see how we will do it. If, if, if, first I will explain you the logic here, that what will happen here. Where is our pen? Okay. Understand my thing carefully. Understand my thing carefully. Go ahead. Sometimes it lags. Okay. So understand my point carefully. Assume this is our array. Okay. There are three questions in it. A, B, C. Okay. So from array.length we will know the total number of questions. From array.length we will know the total number of questions. That means three. Okay. What we have to do is when we are on this question, on the first question, So, after choosing the option, definitely the current index should move forward. Then if it is on this question, then after choosing the option, definitely the current index should move forward. But if it is on the last question, then after ticking the option, then the current index should not move forward. We have to find the last option, that when the last option reaches. Sorry, not the last option, the last question. So, after coming to the last question, we have to stop there. We don't have to increase the current index further. Okay? So, how will we know this? So, I can do this here, that array of array of, array of, I'm so sorry, I'm so sorry, aisa nahi, main aisa kuch condition laga sakta hu, ki current index, current index, Plus 1.

  8. Speaker 2

    Okay.

  9. Speaker 1

    If less than equal to array dot length. Understand this carefully. Why did I do current index plus 1? I did current index plus 1 because I want to see the question. Definitely it will be 0, 1, 2. But according to 0, 1, 2. Although you can do it like this too. Okay. You can do it like this too. Look, first I will tell you like this. Then you will understand this. So, if current index is less than array dot length. So, what does this mean? Current index will come first. Your 0. So, is 0 less than 3? Definitely. So we will do index plus 1. So what will be your current index? Earlier it was 0. Now what will be your current index? It will be 1. So we will check here. Is 1 less than 3? Definitely. So what will be your current index? It will be 2. So here it is. So is it 2 less than 3? Definitely. Then it will go ahead. So we don't have to go ahead. So definitely we have to do index minus 1 here. So that it becomes 2. Index has to go till 2. See here. It has to go till 2. 0, 1, 2. And it should be smaller than 2. It is very simple. Array.length is 3. Length will be minus 1. So this will be the last question. So there should be an increment before the last question. There should not be after that. If there is an increment before the last question, then there should be an increment after clicking on it. There should not be after that. So you can also apply this. This will also help you. So do it and see here. If current index is less than array.

  10. Speaker 2

    Array.

  11. Speaker 1

    Array. Are any, sorry, questions? questions.length-1 if this is the case then only we have to increase the current index otherwise not so reload here again javascript select anything and now we are selecting something so it is not increasing further either do this or do this see position wise in current index do plus 1 and do this here so match position to position that first question second question should not increase after third question or do this as you want to understand from both You can understand here. Okay. So, this is done. Now, what to do after this? Let's reload here. This is happening. Score is also plus. If it is the right option. So, in the last, we have to make the finished one. Is finished or is over. Okay. If it is over, then definitely we have to show results. So, conditional rendering we have to do here. So, definitely we have to make that state here. Cons is over comma set is over is equal to useState, what will we keep in starting, definitely we will keep false in starting, ok, in starting it will not be over, alright, so isOver, isOver, now how will we do conditional rendering, see normal, ternary operator you have read, we will use that, I will write here, if not of isOver is, then definitely you show me questions, ok, And if it is over, then show me the result. We have not made the result yet. Let's come here, rafc. This is our result and here result. Again, understand carefully that it is a normal ternary operator. Ternary operator is normal in any language. If you have read in javascript, So, if not of is over is not over, then show questions, otherwise show results. You can also do this, if is over is over, then show results, otherwise show questions. If this is true, then the first one works, otherwise the second one works. This is done in ternary operator. So if it is over then show the result otherwise show the question. So now what we have to do? Will it work now? Definitely it will not work now. It will not show the result now. Why? Because we have not done is over. So where to do is over? So there are two possibilities. One will be over after the time is over. One will be over when the last question comes. When the last question option is ticked then it will be over. So what will we do here? Here we will do is over. As a prop, we will pass it in the result. Sorry, not in the result. I am so sorry. In the questions. So, in the questions, we will receive this prop. Now, you are getting all these things. I had told you in the previous project too. So here we have received the set is over. Now what to do here? If we don't have the last question, then increment the current index. And if the last question has come, then make the set is over true. It is very simple. Until the last question comes, we are doing index + +, jumping to the next question. And if the last question comes, then we will set the set is over to true. Try to understand it yourself, you will understand it. So if the is over is done, then definitely you should see the result here. Let's do it. So first we selected Python, then we selected CascadingStyle. See the score is also increasing. And if we select 1995, then our result will come. Now there is nothing in the result, we will show you now. Another thing is that when the time is over, your result should be visible here. So it is not visible here when the time is over. So this set is over, you will have to send it in the timer as a props. So here I sent it in the timer too. Here in the timer also came to you. Ok, let's come to the timer and receive it. And as soon as the timer ends, then where was it ending here? If it ends here, that means it becomes zero, then do the clear interval and along with the clear interval, also make the set is over true. Ok, now let's come here and see. Let's reload.

  12. Speaker 2

    3 2 1 0 and finish result is shown here cannot update a component while rendering a different component bad state call ok is something happening here wait a minute so.

  13. Speaker 1

    Basically we are calling the parent state while rendering a child that's why this issue is coming ok while rendering a different component this is what I want to say. So if we remove it in rendering time. Timer is getting updated here. So if we remove it in rendering time. If the timer gets updated here. After that if we put condition here. If left time is less than. If left time is zero. Something like this. If left time is zero. So, if we make set is over true, then I believe it should work. So, in this logic, we don't have to do anything. It is rendering continuously. And here, when time left is actually 0, after that, we try to make set is over true. Let's see if it is working. So, 4, 3, 2, 1, 0. And now it is working perfectly. There is no issue here. So, you can go and read that error by yourself. That what is actually the issue. So here as soon as I changed the logic, your timer was also running during rendering and you were using the state of the app here, that's why the problem was coming. As soon as I removed it from rendering here, the left time is now zero, after that I overset the settings, so this problem has been solved here. So here all our things are working properly. Now we will increase the time a little bit. Everything is not coming right. And we have to show the result. We have to show the score in the result. Now how will we show this? So this is a problematic situation here. We have made the score in the questions. And we have to show in the result. So how will this happen? So definitely we have to make the score in the parent. I told you in depth in the last lecture. In the last project. If we make it in the parent, then it will be easy to send it in both. So we will Instead of making it here, if we had made it here, then definitely our score and set score were working. No, only set score was working. So we have to take set score as a props here. So we will take set score here as a props. From app.jsx, we will send set score in questions. To set score. And we have to use it in result. Where we have to show score? In result. So we will send score here in result. And in result we can show the score here. Result.

  14. Speaker 2

    H2.

  15. Speaker 1

    Your. Score is. Yes your score. And wrap it in a fragment. Now I will give you a recap. You will understand it properly. So this is our app.jsx. And reload now. So 4, 3, 2, 1. And here the result your score is zero. Rest you can do style by using tailwind CSS. I am not going to do that now. It is more important to tell the logic. So this is done. And if the time is not over. If we do question over. Then what happens. So here we increase the timer a little. Instead of 4, we will do 20 for now. We can easily do 3 questions in 20 seconds. So let's reload. So here I have selected our JavaScript correctly. And here there is a cascading style sheet, but I am not selecting this, I am choosing the wrong option. And here the right option is javascript launch 1995. So here I select this, your score is 2. Which is coming perfectly. If I tick all correctly, then javascript cascading style seat and 1995, then your score is 3. So this way you can do it here. And because we have managed the current index ourselves and we are working on the basis of current index. So now no matter how many questions you add here, it will work properly. No matter how many questions you add, you just have to come here in the JSON file. And here in the same format, and keep adding more questions like I am adding more questions here and reloading it and be careful this is your JSON so don't make any mistake here like don't leave any comma I believe we have left it somewhere So, where is the comma? Here it is. The comma has been left. Even if the comma is extra, it still gives an error. So, keep this in mind. So, this was our first question. JavaScript cascading style sheet. After that, 1955. Then it will be repeated. Because I have repeated the same question. So, JavaScript cascading style sheet. And if this question is wrong, we have ticked it. So, your score is 5. There were 6 questions. We have ticked 5. So, 5 scores are coming here. The rest is gone. and your time left is still showing here, so time left should not be visible when it ends, so time left should not be visible, so time left should be visible when our question is being rendered, here time left should be visible, Now let's reload it. You can see our time left, javascript, cascading style sheet, select anything. Now here the result is your score is 4. Now here you can also put a restart button. You don't have to do much, you have to reset the current index, you have to reset the score and reset the time. You have to reset these three things and your proper is back. So, try the restart button by yourself. There are 2-3 things to do. First of all, you have to make the restart button, fix the UI, and see if something else can break in the component or the logic can be better, then you definitely have to do it. After that, we will definitely go to better projects. Although you must have liked this project a little bit. You must have liked it a lot. We have made a timer in it. We also worked on the basis of timer. Along with that, it was a little different concept. We had to manage index from ourselves. You must have got a proper idea of use effect. How it works. Okay. So, it must have been fun. Definitely. Okay. So, according to me, this whole project was made. Rest, you can see. See you in the next lecture. Till then, keep reading. And, bye-bye.