React Quiz App Tutorial (w/ starter code + working example) | Beginner React Projects

Поділитися
Вставка
  • Опубліковано 11 лют 2025
  • In this beginner react project we'll look at how to build a quiz app using React hooks.
    🚨 For more projects check out codecoyotes.com
    🚨 🚨 Starter/Finished Code Repo: github.com/chr...
    Run the STARTER CODE:
    1) git clone github.com/chr...
    2) cd quiz-app/starter
    3) npm install
    4) npm start
    Run the FINISHED CODE:
    1) git clone github.com/chr...
    2) cd quiz-app/final
    3) npm install
    4) npm start
    What we'll learn:
    Managing complex state objects
    Conditionally rendering elements
    Working with multiple state hooks to create a dynamic UI
    🚨 🚨 Get React Project ideas with tips and starter code straight to your inbox: bit.ly/2CoTD6y
    COME SAY HI:
    Blog: www.jschris.com
    Twitter: / chrisblakely01
    Email: hello@jschris.com
    This is a new channel so would love your feedback in the comments.
    Don't forget to like, share, and subscribe! Thanks for watching!

КОМЕНТАРІ • 113

  • @MohamadMohamad-pl4eb
    @MohamadMohamad-pl4eb 3 роки тому +6

    you are the only youtuber than i dont have to speed my video to watch you,
    a lot of stuff with only 12 min, keep it up

  • @Screwfacecapone
    @Screwfacecapone Рік тому +1

    Nice! I tried it out for myself, and altered it to add additional questions and load them from a JSON doc. Thanks a lot!

  • @lacheporter6675
    @lacheporter6675 4 роки тому +11

    Spoilers!!! this is how I made my reset button to reset state (extra credit).
    Just create a function that sets the usestate value back to the orignal value.
    I did name some variables differently. Hope this hint helps for those learning.
    const [currentQuestion, setCurrentQuestion] = useState(0);
    const [showScore, setShowScore] = useState(false);
    const [score, setScore] = useState(0);
    const resetStateClick =()=>{
    setCurrentQuestion (0)
    setShowScore(false)
    setScore(0)
    }
    Put this button inside your score div
    Retry
    For recording the score after hitting retry:
    Add another constant:
    const [recordedScore, setRecordedScore] = useState(0);
    Put this in the resetStateClick from above.
    setRecordedScore(score)
    Add a div.

    Your Last Score: {recordedScore}

  • @santra528
    @santra528 2 роки тому +1

    Thanks Chris for the turtorial. I am new to Angular and I was building quiz app using Angular and I was not sure
    how to go about the logic to calculate the score. Watching this video I was able to implement the logic
    in my quiz app using Angular. Thanks again!

  • @achtube85
    @achtube85 3 роки тому +7

    Thanks for this! I learnt a lot! Subbed right away :)
    I have to confess, though, that I found that, for a non-native English speaker like me, not only your accent is a bit challenging (although beautiful!) but also you speak quite fast, so for the first time ever while watching web dev toturials, I set the speed to x0.75 in order to have enough time to process better :)

    • @ChrisBlakely
      @ChrisBlakely  3 роки тому +1

      Thank you for subbing! Yes I’m still working on talking slower to suit more people, although talking slow doesn’t come natural to me 😂 thanks again for watching !

  • @dimalavrenov3916
    @dimalavrenov3916 2 роки тому

    I am now seriously busy learning react. Initially, I created state, setState, etc. myself, in order to understand how it works under the hood. Now, when I don’t need to write it all by hand, I grasp everything on the fly, so I also understand the theory. Thanks for the lessons. For beginner web developers, this is a very good start. Hello from Russia and thanks again😍

    • @dimalavrenov3916
      @dimalavrenov3916 2 роки тому

      For starters, cheating on a video is a good topic, but then you need to learn how to do it yourself, looking at the code that you previously copied. For example, I do my own social media. car network. In addition, I do such small projects, and I look at the code of people who have been spinning in this area for more than one year, I also do practice at freecodecamp, whoever has not heard of this, I advise! Well, I watch interviews to see how others answer frequently asked questions.

    • @JayLim-bn9fh
      @JayLim-bn9fh Рік тому

      hi, from Pakistan. Goodluck on your coding journey.

  • @mrgames-Will
    @mrgames-Will Рік тому

    Great tutorial, Chris! Thank you!

  • @raynax3702
    @raynax3702 4 роки тому +1

    Your projects are awesome man. Hope you get millions sub soon♥️

    • @ChrisBlakely
      @ChrisBlakely  4 роки тому

      Thanks man!! I hope I get to a million as well 😂

  • @sergiob3698
    @sergiob3698 4 роки тому

    Good luck with your new channel. Thanks for sharing!

  • @musadanjuma6603
    @musadanjuma6603 4 роки тому +1

    Liked and Subscribed immediately, thanks for this tutorial, it is exactly what I was looking for...

    • @ChrisBlakely
      @ChrisBlakely  4 роки тому +1

      Thanks so much , I’m glad you found this helpful !

    • @musadanjuma6603
      @musadanjuma6603 4 роки тому

      @@ChrisBlakely most welcome!!

  • @anasssanba
    @anasssanba Рік тому

    i'm so happy it's my first time doing that quiz app haha it's look the same as yours xD

  • @dimasaaron3759
    @dimasaaron3759 3 роки тому

    Thanks for video, Very useful & GBU Chris.

  • @TheMaxZakh
    @TheMaxZakh 2 роки тому

    Fantastic easy to follow explanation!

  • @AminSani
    @AminSani 4 роки тому +1

    That was very useful , Thank you so much

  • @crazyiron9003
    @crazyiron9003 3 роки тому

    Thankyou OG.Ceb, back to back ti winner.

  • @lucianolimafer6305
    @lucianolimafer6305 4 роки тому +1

    Liked and subscribed. Thanks for this tutorial ..... awesome!!!

  • @muhammadhamzashabbir8364
    @muhammadhamzashabbir8364 4 роки тому

    Oh My God !! You are legend Bro Thank You so much ,,,,,,,you make my day

  • @codingwitheric
    @codingwitheric 2 роки тому

    Great videos man!

  • @bennyakaz
    @bennyakaz 2 роки тому

    Bro this was great, thank you

  • @trungnguyen8252
    @trungnguyen8252 2 роки тому

    thank Chris ! it's useful for me

  • @dmitrbut
    @dmitrbut 2 роки тому

    Thank you man! Good luck!Strong like and subscribe

  • @magdasok-f2i
    @magdasok-f2i 3 роки тому

    nice video, thanks Chris

  • @AzizKhaddaoui
    @AzizKhaddaoui 3 роки тому

    wow very nice. thank you for the show

  • @ThePercivalGlyde
    @ThePercivalGlyde 2 роки тому

    great man thanks

  • @0xk4b1r
    @0xk4b1r 2 роки тому

    amazing, thanks..

  • @dubbsy_
    @dubbsy_ 2 роки тому +1

    Awesome video man... how would you add in Fade-out / fade-in style transitions between questions?

  • @bhaveshkumarreddy46
    @bhaveshkumarreddy46 4 роки тому

    Simply Superb

  • @ferrino4145
    @ferrino4145 4 роки тому

    You did some serious magic here Sir, and also saved my...programme :D

  • @ahusyn
    @ahusyn 2 роки тому +1

    I see you have a css class for .correct and .incorrect ready to show if the answer was correct or not, however I wanted to see how that could be implemented? once clicked on answer, where would that go?

  • @ichbindiego19
    @ichbindiego19 4 роки тому

    Muchas gracias excelente, saludos desde México.

  • @Mona_prs_7878
    @Mona_prs_7878 8 місяців тому

    Perfect

  • @OleksandrRaduka
    @OleksandrRaduka 2 роки тому

    thanks

  • @hritikchaudhary5470
    @hritikchaudhary5470 3 роки тому

    Awesome 👍

  • @NotiCuriosidades
    @NotiCuriosidades 2 роки тому +1

    Hi. Great video. A couple of questions. Is it possible to display the questions and answers randomly? 2. Is it possible to see the questions and correct answers at the end? I.e. see all the questions along with the correct answers.

  • @shaheensiddiqui1952
    @shaheensiddiqui1952 2 роки тому

    sit it was so much useful

  • @TopTalentBridge
    @TopTalentBridge 4 роки тому +2

    Hello chris,
    I am not able to the logic of displaying the previous state please help me with it please share the code

    • @Abogida11
      @Abogida11 4 роки тому

      I think you need to save the scores in Local storage and display it

    • @lacheporter6675
      @lacheporter6675 4 роки тому

      Check my above comment if your still stuck might help

  • @replayzor
    @replayzor 2 роки тому

    This is so easy too bad you don't make them anymore they are so helpfull Thanks

  • @frankagu924
    @frankagu924 2 роки тому

    Beautiful

  • @وليدالنادي-ح3ق
    @وليدالنادي-ح3ق 3 роки тому

    Thanks Alot

  • @DhiaMagicien
    @DhiaMagicien 3 роки тому

    I F**king love this tutotial ❤
    Its so excellent dude !
    Maybe u can reDo it again with a countdown Timer?

    • @ChrisBlakely
      @ChrisBlakely  3 роки тому +1

      Haha thanks Dhia!
      Yeah I went a bit too fast in this video so I'm planning to do a second version, maybe using Redux/context API as well.

  • @Bep33
    @Bep33 3 роки тому +1

    Great vid! How would you make the correct option turn green to show the user they got the answer right?

  • @hariskhan804
    @hariskhan804 4 роки тому

    brilliant

  • @SatyamGupta-yq1pt
    @SatyamGupta-yq1pt 3 роки тому

    Thanks bro

  • @juguetestoys1137
    @juguetestoys1137 3 роки тому +1

    Hi, your video is great.
    How can I put an Alert (this answer is incorrect, the correct answer is .... HERE SHOW THE CORRECT ANSWER")

  • @yuvanhanwat9929
    @yuvanhanwat9929 2 роки тому

    If we want to show all questions in only one page then what should be the changes in this code. Please help.

  • @rangabharath4253
    @rangabharath4253 4 роки тому +1

    awesome

  • @andresramirez4469
    @andresramirez4469 2 роки тому +1

    i did my own quiz, (Similar to yours but i used form and split up components, and used radio buttons) but when i was trying to do the score i had so much trouble getting it to increment the score. Until i looked at your video. I dont see how putting in answerOption.isCorrect as an argument at the handleAnswerButtonClick would make it work. Could you explain that or somebody else on here?

    • @osuntuyiemilos5803
      @osuntuyiemilos5803 2 роки тому

      Hi, I also tried radio buttons but when I click on one option the other options on the next question gets clicked also. How did you navigate this issue? Thanks

  • @elsaiedsamaka7373
    @elsaiedsamaka7373 4 роки тому

    nice and easy ,thank you +_+

  • @Rupali_-pk1jk
    @Rupali_-pk1jk 3 роки тому +3

    plz give css of this project

  • @mohammedshoaib2755
    @mohammedshoaib2755 3 роки тому

    Great

  • @renatico7733
    @renatico7733 2 роки тому

    Great video, I want to do a different quiz where each answer gives some points, like answer1 gives 1 point and so on, and the correct answer gives 5 points. At the end of the Quiz it sums up all the points and shows them to the user, any clues to implement this point system here?

    • @veterancode2523
      @veterancode2523 2 роки тому

      Try this videos it will help you ua-cam.com/video/_Vq1Ba26lX4/v-deo.html

  • @yeminhtun2543
    @yeminhtun2543 3 роки тому

    great..

  • @windzordave2411
    @windzordave2411 3 роки тому +1

    That's awesome man! However, how do I get the value(string) of the user's choice?

    • @ChrisBlakely
      @ChrisBlakely  3 роки тому +2

      Thanks for the comment man - I can't exactly remember this but I'm pretty sure there is an onClick function that gets called when the user clicks an answer, you could get it from within that function and store it in state or whatever

    • @windzordave2411
      @windzordave2411 3 роки тому +2

      @@ChrisBlakely Yep! I figured it out. Your work is a great help! Thank you

  • @saldanasal1353
    @saldanasal1353 2 роки тому

    Is possible to save the answers into SQL ?

  • @joyprokash4016
    @joyprokash4016 3 роки тому

    damn fast talking style :3

  • @DonovanNagel
    @DonovanNagel 4 роки тому

    How would you add a 'Click to start again' button to this?

    • @ashprasad9075
      @ashprasad9075 4 роки тому +2

      When the code displays the score, set a button which will display the first question and set score to 0

    • @veterancode2523
      @veterancode2523 2 роки тому

      ua-cam.com/video/_Vq1Ba26lX4/v-deo.html

  • @zekisebsib6061
    @zekisebsib6061 2 роки тому

    what if i want an image instead of a text message?? can some one help me out

  • @turgutguvercin927
    @turgutguvercin927 2 роки тому

    There are 8 books in the Harry Potter Series.

  • @varshas565
    @varshas565 3 роки тому

    when answer is correct and incorrect how we display colors

    • @ChrisBlakely
      @ChrisBlakely  3 роки тому +1

      use a template string to apply a class to the background depending on the isCorrect boolean (or whatever I named it)

  • @kulsoomsiddiqui7425
    @kulsoomsiddiqui7425 4 роки тому

    I score 4 and wanna show that you are lost. how can i do it?

    • @shubhambhavsar23
      @shubhambhavsar23 4 роки тому

      Hey, inside of score section add this {score < questions.length ? Try again : You won!}

    • @veterancode2523
      @veterancode2523 2 роки тому

      ua-cam.com/video/_Vq1Ba26lX4/v-deo.html

  • @abdullahajmal6888
    @abdullahajmal6888 4 роки тому

    react native ?

  • @thomasters9427
    @thomasters9427 4 роки тому

    good tutorial but rather than go at a million miles an hour, why dont you just slow down and make the video longer?

    • @ChrisBlakely
      @ChrisBlakely  4 роки тому

      Thanks for the feedback! Yep I’m still trying to find the balance between speed and video length :)

    • @vataidomonkos1783
      @vataidomonkos1783 3 роки тому +1

      @@ChrisBlakely I really liked the speed. You can download the files and follow what he is doing. I personally like pausing and rewinding past 10-20 seconds if i don't understand something, more than having to increase the play speed because i'm watching the dude mistype something 4th time or simply because he speaks super slowly and loses his train of thought.
      Thanks for the vid, was super helpful to me.

  • @Emma2491
    @Emma2491 2 роки тому

    Please calm down when you speak :)

  • @a_dev7599
    @a_dev7599 3 роки тому

    Thanks for the tutorial. I am trying to change border color depending if the answer is correct or wrong with template literals, as suggested but I am doing ir wrong. Please advise how to correct it: {
    handleAnswerOptionClick(answerOption.correct);

    }}>

    • @sherazliaqat2814
      @sherazliaqat2814 2 роки тому

      try this className={`button ${
      answerOption.isCorrect ? "correct" : "incorrect"
      }`}

    • @veterancode2523
      @veterancode2523 2 роки тому

      ua-cam.com/video/_Vq1Ba26lX4/v-deo.html

  • @venkatapenumatsa3959
    @venkatapenumatsa3959 3 роки тому

    did anyone figure out, how to add the "Start Again" button at the end of the quiz? I added the below code and seem nothing is happening...! Appreciate any help

    You scored {score} out of {questions.length}
    setCurrentQuestion(0)}
    >
    Reset

  • @dejansekulic4199
    @dejansekulic4199 3 роки тому

    Good luck with your new channel.Thanks for sharing!

  • @noumankhan4381
    @noumankhan4381 2 роки тому

    thankyou

  • @tumon001
    @tumon001 3 роки тому

    Thanks Bro