Code Monkey home page Code Monkey logo

week10-kj's People

Contributors

jessica440 avatar khadija-nur avatar

Watchers

 avatar  avatar  avatar

week10-kj's Issues

Time is too short

Time is not long enough to read the questions and think about the right answer.

Great Quiz

Really live the idea and the punny name ☺️

Timer

The sessions must have a timer at the top - 30 secs for each question

Render based on state (rather than directly DOM manipulate)

if (event.target.textContent === correct_answer) {
event.target.className = "green";
setTimeLeft(timeLeft + 5);
props.setScore(props.score + 1)
} else {
event.target.className = "red";
setTimeLeft(timeLeft - 2);
}

This is kind of a subtle React philosophy thing, but you should generally be suspicious if your code ever has to touch the real DOM. React is designed to handle all DOM updates for you, so if you're ever doing a querySelector or directly changing classNames etc that's usually something to avoid.

Remember your component re-runs whenever state changes, which means you can put conditions and dynamic stuff into your JSX to determine e.g. what classNames elements should have. You just need to have state values that let you know what to render.

E.g.

{shuffledChoices.map(choice => (
  <button
    // if we have chosen this button, then if the answer is correct make it green otherwise red
    className={selectedChoice === choice && (selectedChoice === correct_answer ? "green" : "red")}
    onClick ={() =>{
      setSelectedChoice(choice); // store the selected choice in state
      setIndex(index + 1)
    }}
  >
    {choice}
  </button>
))}

Generally React updates are a lot easier to manage if you do as little logic as possible in event handlers and try to just make them simple state updates. You can then use the updated state in your render to determine what the page should look like.

Hard to follow code

The code was a little difficult to follow but that's probably due to our lack of understanding of react that your code πŸ˜…

This is also something we forgot to do but comments would've helped us understand the code more.

We couldn't understand what you were doing with the array of correct and incorrect answers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.