Git Product home page Git Product logo

trivia's Introduction

logo

Trivia

GOAL: You will be building a Trivia app that will fetch data inside a componentDidMount, pass props to children components, and initialize and update state via this.setState. Together we’ll build the Trivia app to have just 1 question with a random category, but there will be plenty of additional features you can add on your own time!

Setup

  • Fork this repo, clone to your desktop, and install dependencies:
    npm install
  • Start the server, and navigate to localhost:1234
    npm run start
  • Lint the JavaScript
    npm run lint

Directions

  1. In App.js, fetch a trivia question from the provided API
    • Use the TRIVIA_API constant. console.log() the response from the API to see the structure of the response.
    • Store the response question in state. You’ll have to initialize state for this as well. Since the response from the API will be a complex object, initialize state.question as null, so we can check if a question is present or not.
  2. Use the Question component that’s imported into App and conditionally render it and pass the question on state to it.
    • Note: We’ll have to conditionally render the <Question /> component. If the data from the API has not yet returned and this.state.question is still null, we don’t want to render the component yet.
    {this.state.question && <Question question={this.state.question}} />}
  3. You’ll notice that Question is already rendering an AnswerButton component, but clicking on an answer button doesn’t do anything yet. We need to pass this.handleGuess to AnswerButton.
    • Notice that handleGuess expects a single argument of answer to be passed to it. Figure out how we should pass answer into handleGuess!
  4. Now that we have the question rendering, answer buttons rendering, and an ability to guess an answer, we need to tell the user if they answered correctly or not!
    • In Question below the answers, dynamically render some content!
    • If this.state.guessed is truthy, render a div
  5. Inside the div, if this.state.guess === this.props.question.correct_answer then this means the user answered correctly!
    • Let them know they are correct by rendering a helpful “Correct!” message.
    • If they answered incorrectly, we’ll say Incorrect! The correct answer is _____

Made with ♥️ at Multiverse

trivia's People

Contributors

calamityadam avatar stevenjlance avatar wallacepreston avatar

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.