Learn localStorage by Building a Todo App - Step 36

Tell us what’s happening:

Its asking that “You should move the dataArrIndex variable into the addOrUpdateTask function.”

Your code so far

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

/* file: styles.css */

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

const addOrUpdateTask = ()=>{
   if (dataArrIndex === -1) {
    taskData.unshift(taskObj);
  }

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn localStorage by Building a Todo App - Step 36

You are going to remove almost an entire block of code from the bottom of the file plus what you have already. From what I can tell it’s just a matter of cut, copy and paste, after creating the arrow function.

I still don’t get it, Im crying right now :smiling_face_with_tear:

Hi @brianreyfuentesvarga

For this step you need to cut and paste a variable, an object, and an if statement.

Please reset the step and try again, later is fine.

Happy coding

taskForm.addEventListener(“submit”, (e) => {
e.preventDefault();

const dataArrIndex = taskData.findIndex((item) => item.id === currentTask.id);
const taskObj = {
id: ${titleInput.value.toLowerCase().split(" ").join("-")}-${Date.now()},
title: titleInput.value,
date: dateInput.value,
description: descriptionInput.value,
};

if (dataArrIndex === -1) {
taskData.unshift(taskObj);
}

taskData.forEach(
({ id, title, date, description }) => {
tasksContainer.innerHTML += <div class="task" id="${id}"> <p><strong>Title:</strong> ${title}</p> <p><strong>Date:</strong> ${date}</p> <p><strong>Description:</strong> ${description}</p> <button type="button" class="btn">Edit</button> <button type="button" class="btn">Delete</button> </div>
}
);

reset()
});

this is what i cut ad pasted.

Hi @brianreyfuentesvarga

First:

Use arrow syntax to create an addOrUpdateTask function.

Then move:

  1. the dataArrIndex variable,
  2. the taskObj object,
  3. and the if statement into the addOrUpdateTask function.

Happy coding

I’m never gonna finish this task :frowning: