Giter Club home page Giter Club logo

listeners-and-handlers's Introduction

Listeners & Handlers

This repository contains a some mini-websites for you to study and practice developing. Each one has some HTML a few listeners and handlers with blanks to fill in, and each one is organized the same way. The goal of these exercises isn't to create mind-blowing projects. Instead the goal to get lots of practice reading code, debugging and stepping through in the debugging.

You should already know a little about events before getting working on these exercises, head over to study.hackyourfuture.be to find some starting resources


debugger

These exercises are as much about practicing using the DevTools Debugger as it is about learning Events and Handlers. After connecting the event listeners to the correct DOM elements, you will find that it's possible to pass all of the asserts just by investigating local variables in you Debugger.

So keep your DevTools open and study away!


How to do the exercises

To complete the exercises you should copy-paste the code from challenge.html into the file solution.html, this will help you go back to the beginning when you make mistakes and to review what you learned later.

Each challenge.html contains multiple blanks (_) to fill in. Your task is to replace each one with the correct word. All of the words you need to fill in the blanks are already somewhere in the challenge, you just need to find them!

For example in the first exercise:

<head>
  <script id='handlers'>
    function handler(event) {
      debugger;
      console.assert(event.target.innerHTML === '_', 'event.target.innerHTML');
      console.assert(event.target.nodeName === '_', 'event.target.nodeName');
      console.assert(event.target.id === 'hi', 'event.target.id');
      console.assert(event.target.className === 'secret', 'event.target._');
      console.assert(event.type === 'click', 'event.type');
    }
  </script>
</head>
<body>
  <section id='user-interface'>
    <button id='hi' class='secret'>catch me if you can!</button>
  </section>

  <script id='listeners'>
    document.getElementById('_').addEventListener('_', _);
  </script>
</body>

The best way to solve the exercises is to start by studying the code in <script id='handlers'>, and working "backwards" from there. This will help you know what you are looking for in the rest of the file, for example in the code above:

  • event.type === 'click' shows that you should be adding a "click" event, so you can fill in the event type like this: document.getElementById('_').addEventListener('click', _);
  • event.target is the HTML element that the event is attached to. So when you see event.target.id === 'hi' in the handler, you can fill in the event listener like this: document.getElementById('hi').addEventListener('click', _);

An enormous part of programming is actually just reading! Spotting relationships between lines of code, or finding small changes or mistakes in a file of code is a crucial skill to develop.

To get an idea of how this works, it will be very helpful to start by studying the completed example. Open both the example challenge.html and the example solution.html in Visual Studio Code and compare them side-by-side, can you find find how each blank was filled in?


The Exercises



Hack Your Future: Belgium

listeners-and-handlers's People

Contributors

colevanderswands 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.