diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-localstorage-by-building-a-todo-app/64e4eec13546c06d61a63d59.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-localstorage-by-building-a-todo-app/64e4eec13546c06d61a63d59.md index e7efd346a9c..c9794ade15b 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-localstorage-by-building-a-todo-app/64e4eec13546c06d61a63d59.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-localstorage-by-building-a-todo-app/64e4eec13546c06d61a63d59.md @@ -7,22 +7,22 @@ dashedName: step-11 # --description-- -You need to determine whether the task being added already exists or not. If it doesn't exist, you will add it, and if it already exists, you will set it up for editing. You can use the `findIndex()` method to accomplish this. +You will need to determine whether the task being added to the `taskData` array already exists or not. If the task does not exist, you will add it to the array. If it does exist, you will update it. To accomplish this, you can use the findIndex() method. -`findIndex` is an array method that lets find the index of the first element in an array that satisfies a given testing function. +The `findIndex()` array method finds and returns the index of the first element in an array that meets the criteria specified by a provided testing function. If no such element is found, the method returns `-1`. Here's an example: ```js -const numbers = [3, 1, 5, 6, 10, 9, 8]; -const firstEvenNumIndex = numbers.findIndex((num) => num % 2 === 0); +const numbers = [3, 1, 5, 6]; +const firstNumLargerThanThree = numbers.findIndex((num) => num > 3); -console.log(firstEvenNumIndex); // Output: 3 – because the first even number (6) is at index 3 +console.log(firstNumLargerThanThree); // prints index 2 ``` -Declare a `dataArrIndex` variable using `const` and set it to the result of the `findIndex()` method applied to the `taskData` array. Utilize arrow syntax to provide a callback function with `item` as the parameter, and within the callback, check if the `id` property of `item` is equal to the `id` property of `currentTask`. +Use `const` to declare a variable called `dataArrIndex` and assign it the value of `taskData.findIndex()`. For the `findIndex()` method, pass in an arrow function with `item` as the parameter. -If the task exists, this returns the index, and if it doesn't exist, it returns `-1`. +Within the arrow function, check if the `id` property of `item` is strictly equal to the `id` property of `currentTask`. # --hints--