Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal review #4

Open
yersel500 opened this issue Feb 21, 2022 · 0 comments
Open

Internal review #4

yersel500 opened this issue Feb 21, 2022 · 0 comments

Comments

@yersel500
Copy link
Owner

yersel500 commented Feb 21, 2022

I can improve the next part of my codes:

to-do-list/src/index.js

Lines 25 to 40 in 659775d

ulContainer.addEventListener('click', (e) => {
const index = Number(e.target.parentElement.classList[0]);
if (e.target.classList.contains('fa-trash-can')) {
listofTasks.deleteTask(index);
printTask(listofTasks);
listofTasks.saveLocalStorage();
} else if (e.target.classList.contains('fa-square')) {
listofTasks.tasks[index - 1].complete = true;
printTask(listofTasks);
listofTasks.saveLocalStorage();
} else if (e.target.classList.contains('fa-square-check')) {
listofTasks.tasks[index - 1].complete = false;
printTask(listofTasks);
listofTasks.saveLocalStorage();
}
});

  • Include a specific function instead of writing it directly on the event listener.

ulContainer.appendChild(taskContainer);
taskContainer.onclick = (e) => eraseTask(e, index, task, complete);

  • Instead to add a click event inside the print task function, could be better if you do it externally. It will help to avoid possible bugs when users click on the tasks.

Happy coding! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant