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

Do I follow JavaScript best practices? #4

Open
2 tasks
Camilovelag opened this issue Oct 3, 2022 · 0 comments
Open
2 tasks

Do I follow JavaScript best practices? #4

Camilovelag opened this issue Oct 3, 2022 · 0 comments

Comments

@Camilovelag
Copy link
Owner

Good day, @Camilovelag (from myself to myself πŸ˜†)

Your app looks pretty good, but in order to improve it, I would like to suggest the following changes:

done

πŸ› οΈ Changes to do

JavaScript best practices

  • Keep the application logic separated from DOM manipulation tasks. In this case, try splitting these features into separate js files.
    // Update checkbox status
    checkbox.addEventListener('change', () => {
    task.completed = checkbox.checked;
    localStorage.setItem('taskArr', JSON.stringify(parsedArr));
    if (task.completed) {
    taskText.style.textDecoration = 'line-through';
    } else {
    taskText.style.textDecoration = 'none';
    }
    });
    // Update task description
    taskText.addEventListener('click', (e) => {
    e.preventDefault();
    updateBtn.style.display = 'block';
    deleteBtn.style.display = 'none';
    taskText.style.backgroundColor = '#f4f4f4';
    });
    taskForm.addEventListener('submit', (e) => {
    e.preventDefault();
    const input = Object.fromEntries(new FormData(e.target));
    task.description = input.description;
    localStorage.setItem('taskArr', JSON.stringify(parsedArr));
    updateBtn.style.display = 'none';
    deleteBtn.style.display = 'block';
    taskText.style.backgroundColor = '#fff';
    });
    // Delete task
    deleteBtn.addEventListener('click', (e) => {
    e.preventDefault();
    let temp = parsedArr.filter((item) => item !== task);
    parsedArr = temp;
    temp = parsedArr.map((item) => {
    item.index = parsedArr.indexOf(item) + 1;
    return item;
    });
    parsedArr = temp;
    localStorage.setItem('taskArr', JSON.stringify(parsedArr));
    taskList.removeChild(taskItem);
    });
    return taskList;
    });
    }

DRY, KISS, YAGNI

Optional suggestions

No optional changes/suggestions to add.

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