Giter Site home page Giter Site logo

events_lab's Introduction

Events Lab

To-Do list

Our app will have the following items:

  • An h1 title (e.g. "My To-Dos").
  • A single ul tag, empty when the page is first loaded.
  • A form for the user to add a new to-do, with a single text input and a submit button.

And the following functionalities:

  • When the user writes something in the form's text input area and clicks submit, the ul should update with a new li item at the bottom of the list. The page should not refresh.

    Hints/Steps
    1. Add an event listener to the form with .addEventListener. What event do you want to listen for?
    2. Remember, what does event.preventDefault() do?
    3. Grab the value the user typed from the text input. Do you remember what property of the input node has this?. If not Google it or ask a peer.
    4. Create new li element with document.createElement(). Set its innerText property to be the text the user typed.
    5. Don't forget to append the created li to the list.
  • When the user writes nothing in the form's text input area and clicks submit, an error message (inside a p tag) should appear below the form.

    Hints/Steps
    1. How can you check if the input text has something typed or not?
    2. Have an empty paragraph that is above the <ul> and under the <form>. If the user didn't type anything, modify the content of the paragraph to display a text like: 'Error. Todo cannot be empty'
  • When the user clicks on one of the li items, the item should be crossed out, indicating that that to-do is complete. You will need to look at [element].style.textDecoration for the cross out effect. Look at all the different text decoration options.

    Hints/Steps
    1. You will need to add an event listener to all the li elements. What event do we want to listen for? What is a downside of this? Talk to a peer or ask an instructor.
    2. There is a better option than 1. Add the event listener to the list itself (parent of all lis) and take advantage of event bubbling. If you don't remember what this is check the lecture video again.
    3. Once you know what element the event occurred on (event.target) checkout [element].style.textDecoration to put a line through the text and get the todo cross out effect.

Sample

todos being added to todo list

Bonus Tasks

  • Have the input go back to empty after adding a new todo.
  • Implement a delete button next to each li that removes that li tag entirely.
  • Clicking a todo that is crossed out (completed) uncrosses the todo.
  • Add the ability to add multiple to-dos if the user submits a text input with multiple lines. Each line should be a new to-do.
  • Look at the next lesson Intro to CSS and add some styling to your app.

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.