Learn localStorage by Building a Todo App - Step 57

Tell us what’s happening:

Please help me out. I have issue with step 57.

You also want a deleted task to be removed from local storage. For this, you don’t need the removeItem() or clear() methods. Since you already use splice() to remove the deleted task from taskData, all you need to do now is save taskData to local storage again.

Use setItem() to save the taskData array again. Pass in data as the key and ensure that taskData is stringified before saving.

The below is what i did but it didnt pass.

localStorage.setItem(‘data’, JSON.stringify(taskData));
taskData.splice(dataArrIndex, 1);

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

localStorage.setItem('data', JSON.stringify(taskData));
 taskData.splice(dataArrIndex, 1);

 

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

Challenge Information:

Learn localStorage by Building a Todo App - Step 57

That seems odd because I’m certain your code would definitely pass. What sort of message did the challenge give you?

Your code is passing for me.

But you shouldn’t have taskData.splice(dataArrIndex, 1); after the localStorage code.

If you moved that line of code from it initial location, the test will fail. But if you just duplicated the code it should still pass (but you still shouldn’t have it).


Just to be clear:

This will fail:

const deleteTask = (buttonEl) => {
  const dataArrIndex = taskData.findIndex(
    (item) => item.id === buttonEl.parentElement.id
  );

  buttonEl.parentElement.remove();

  localStorage.setItem('data', JSON.stringify(taskData));
  taskData.splice(dataArrIndex, 1);
}

This will pass:

const deleteTask = (buttonEl) => {
  const dataArrIndex = taskData.findIndex(
    (item) => item.id === buttonEl.parentElement.id
  );

  buttonEl.parentElement.remove();

  taskData.splice(dataArrIndex, 1);
  localStorage.setItem('data', JSON.stringify(taskData));
  taskData.splice(dataArrIndex, 1); // none the less, this should not be here 
}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.