Tell us what’s happening: i already used arrow syntax to create an addOrUpdateTask, but i have difficulty moving the dataArrayIndex variable and taskObject object and the if statement into the addOrUpdateTask function
Your code so far
WARNING
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.
const addOrUpdateTask = (dataArrIndex, taskObj) => {};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0
Challenge Information:
Learn localStorage by Building a Todo App - Step 30
1 Like
nald00
January 27, 2024, 10:59am
2
I havent reached this step yet but perhaps put an empty if inside the {}.
1 Like
tried that, and it still didnt pass
1 Like
nald00
January 27, 2024, 1:03pm
4
Done it now.
There are no parameters in ()
Move the two const for dataArrIndex, taskObj into the {}
1 Like
nald00
January 27, 2024, 1:05pm
5
also the if statement after them
1 Like
i did that, the code still wont pass: const addOrUpdateTask = () => {dataArrIndex, taskObj}; if(){}
1 Like
I am yet to figure out how to pass this level
1 Like
You have to move literaly, everything to the function. Put everything inside the {body}. There are no parameters.
Happy code!
1 Like
nald00
February 3, 2024, 10:05am
9
cut and paste lines 50 to 60 and put them inside the {}
2 Likes
the lines of code you need to put inside { } are the lines of codes inside the taskForm. addEventListener at line 60
1 Like
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.unshift(taskObj);
}
}
2 Likes
I have the same code, but it still do not pass?
1 Like
copy my code and compare yours with it or send your code
1 Like
My code
‘’’
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.unshift(taskObj);
}
};
‘’’
1 Like
You forgot to use the backticks.
`This is how you use template literals with backticks ${variable}`
1 Like
I added the the backticks , but still do not pass?
Blockquote
const addOrUpdateTask = () => {
const dataArrIndex = taskData.findIndex( () => 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);
}
};
Blockquote
It seems to me that the backticks are not to be seen in the code that I copied?
1 Like
place your code in between these:
```
place your code here
```
Or please create a new topic for your issue so i can see your whole code and help you better.
1 Like
I added the the backticks , but still do not pass?
const addOrUpdateTask = () => {
const dataArrIndex = taskData.findIndex( () => 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);
}
};
Now my is displayed in a right way.
Why this code do not pass?
1 Like
Here, you forgot to use the item as a parameter for your callback function.
1 Like
My code is now:
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.unshift(taskObj);
}
};
I added the item as a parameter for your callback function.
My code still do not pass?
1 Like