Coder Social home page Coder Social logo

js-mini-challenge-events's Introduction

JS Mini Challenge: Event Handling

In this challenge, we're going to keep working on Ian's Liverpool fan page and give our users the ability to:

  • Toggle the header color
  • Add new players
  • 'Like' a player

We've got some starter code already written for us (this should look somewhat familiar from the previous challenge). Your job is to add some additional functionality to make our app more dynamic by handling user interactions.

There's a section in this Readme file for your notes on each deliverable. As you go through the deliverables, write down some notes in this file on how you solved each problem. It'll help reinforce what you learned and give you a head start next time you see a similar problem.

Deliverable 1: Toggle Header

When a user clicks the header, the color should toggle between black and red.

To get you started, there's a helper function already written takes in an element and toggles its color that you can use. You can try it out in your console:

toggleColor(document.querySelector("h1#header"))

Try calling it a few times to see the color switch back and forth.

Once you have it working in the console, write an event listener that will use this helper function to change the color of the header when a user clicks on it.

YOUR NOTES


Deliverable 2: Create Player

Our app already has a few players in it (check out the starter code in index.js to see how the initial render is set up), but we want our users to have the ability to add additional players by entering the player's details in the form#new-player-form.

When a user submits the form, the new player should be displayed on the bottom of the page (you can use the renderPlayer helper function from the starter code if you like). The data won't persist (when you refresh the page, the new player won't show up) - we'll see how to fix this later in the mod. For now, focus on getting the player on the page when the form is submitted!

Some things to keep in mind:

  • If you see the page refresh, consider adding some code to prevent the default behavior of a form submitting.
  • Make sure you're using the form submit event, not the click event.
  • You can use the name attribute of the input elements as an easy way to reference the input fields within the form. For example: document.querySelector("#new-player-form").nickname will look inside the form#new-player-form and return the input element with the name='nickname' attribute
  • Once you have access to an input field, you still need to retrieve its value to see what the user entered in the form!

YOUR NOTES


Deliverable 3: Like Button

When a user clicks the like button for a player, that player's likes should increase by 1.

You can decide if you'd like to use event delegation to handle this, or if you'd like to attach individual event listeners to each like button. Regardless of the approach you take, the like button feature should work for all players (including new players that get added when a user fills out the form).

YOUR NOTES


js-mini-challenge-events's People

Contributors

jessicasalbert avatar ihollander 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.