Open terehov-ar opened 2 years ago
Step 1: Create the following elements in the HTML structure:
Step 1: Create the following elements in the HTML structure:
- A text field
- A button with the text "add"
- An empty list-container for todo items (they'll be added later using javascript)
done
Step 2: Write a script to provide the following functionality:
li
element containing the provided text, and append it inside the list element.Step 2: Write a script to provide the following functionality:
- On button press, if the text field contains some text, create a new
li
element containing the provided text, and append it inside the list element.- On button press, if the text field contains no text, do nothing
done
Step 3: Clear the text field on element addition:
Step 4: Create a data structure for storing the app's state
{ id: string, text: string, createdAt: number }
where id
is a random uuid generated on the fly (please use this method for generating the uuid), text
is the text which was taken from the input text field, and createdAt
is a timestamp at the moment of the element additionStep 5: Create the update function which should do the following
ul
element off all child elementsli
element with the text
of the current iteration item inside of it and the id
added to it as a data-attribute (please call it data-id
)ul
Then, remove the logic for creation and addition of li
elements from the button click handler callback
Then, call the update
function in the end of the button click handler callback
Step 6: Make use of local storage for state persistence
save
which stringifies and stores the state
array in the local storage under the key 'state'
load
which pulls the state out of the local storage, then parses and populates the state
array with itsave
function at the end of the update
functionload
function on the script startupStep 7: Implement item delete functionality
li
element create a delete
buttonIf you're feeling unstoppable, you can try to implement the event delegation here. It is a useful concept to understand as it greatly improves performance when dealing with a big amount of data
create app with html css js