Learn localStorage by Building a Todo App - Step 30

Tell us what’s happening:

Hi, I am stuck here. I dont know which part is wrong, already followed the instructions. Can anyone help to check which part I wrongly do?

Use arrow syntax to create an addOrUpdateTask function. Then move the dataArrIndex variable, the taskObj object, and the if statement into the addOrUpdateTask function.

Error thrown:
You should move the if statement with the condition dataArrIndex === 1 into your addOrUpdateTask function

Your code so far

const addOrUpdateTask = () => {
  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.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>



The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

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

Challenge Information:

Learn localStorage by Building a Todo App - Step 30

Welcome to our community!

You have deleted some code lines from the challenge which shouldn’t be erased. Check all again.
After the if statement, you must close the addOrUpdateTask function with the right curly brace }.

Sorry but i still don’t get it :frowning: i didn’t erase any code lines from the challenges and already close the function with the right curly brace

Could this error by a mistake in the creation of the exercise. I also get " You should move the if statement with the condition dataArrIndex === 1 into your addOrUpdateTask function." but I can only pass when i use -1 instead of 1.

The findIndex() method returns -1 when it doesn’t find anything. In the exercise mentioned, we need to check if there is no element found with the same id. If there’s no existing element with the same id, we add a new element to the taskObj . Otherwise, we edit the existing task element.
Your code(below) is wrong as if it is equal to 1 then we have to edit the task element not add it as you are doing using unshift() method.
if (dataArrIndex === 1) {
So, please change “1” to “-1” to pass the exercise.
Please ignore my bad English I am learning it .