Tell us what’s happening:
Currently stuck on this step is there something i might be missing please help.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const deleteTask = (buttonEl) => {
const dataArrIndex = taskData.findIndex(
(item) => item.id === buttonEl.parentElement.id
buttonEl.parentElement.remove();
taskData.splice(dataArrIndex, 1)
);
}
// 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/130.0.0.0 Safari/537.36
Challenge Information:
Learn localStorage by Building a Todo App - Step 44
Teller
November 7, 2024, 8:14pm
2
Hi @daylightattack
Since you have more than one expression, you need to wrap them in curly braces.
Happy coding
The whole code is wrapped in curly braces can you provide more clear instructions?
You added the two lines of code inside the findIndex
callback. They should be after the findIndex
code.
What @Teller means is that an arrow function should have curly braces around the code to be executed if there is more than one expression within it. An implicit return (no curly braces) works if there is one expression to be returned. If you make the change suggested it will pass.
@lasjorg suggested a different way, which also works.
lasjorg
November 7, 2024, 10:19pm
6
It is a bug that you can pass the challenge with the code inside the callback. You do not have access to dataArrIndex
inside the callback, and it is used by the splice call.
It’s just because it is using a regex for the test.
https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-localstorage-by-building-a-todo-app/64faf874364ec308f875f636.md
opened 10:26PM - 07 Nov 24 UTC
scope: curriculum
status: waiting triage
new javascript course
### Describe the Issue
The regex test allows you to pass with this code.
```js…
const deleteTask = (buttonEl) => {
const dataArrIndex = taskData.findIndex(
(item) => {
item.id === buttonEl.parentElement.id
buttonEl.parentElement.remove();
taskData.splice(dataArrIndex, 1)
}
);
}
```
### Affected Page
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-localstorage-by-building-a-todo-app/step-44
### Your code
```
```
### Expected behavior
To not pass with incorrect code.
### Screenshots
_No response_
### System
- Device: [e.g. iPhone 6, Laptop]
- OS: [e.g. iOS 14, Windows 10, Ubuntu 20.04]
- Browser: [e.g. Chrome, Safari]
- Version: [e.g. 22]
### Additional context
Forum: https://forum.freecodecamp.org/t/learn-localstorage-by-building-a-todo-app-step-44/719638/4