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

Improving code following HTML, CSS and JS best practices #6

Closed
2 of 4 tasks
indigodavid opened this issue Jun 6, 2022 · 1 comment
Closed
2 of 4 tasks

Improving code following HTML, CSS and JS best practices #6

indigodavid opened this issue Jun 6, 2022 · 1 comment

Comments

@indigodavid
Copy link
Owner

indigodavid commented Jun 6, 2022

Reviewing the code I have found the following functions that can be improved following the "Best Practices" recommended for JS, HTML, and CSS:

  • In the following lines I am repeating myself. Maybe I can refactor my code to improve this code.

    checkbox.classList.add('check');
    checkbox.setAttribute('type', 'checkbox');
    checkbox.setAttribute('name', `check${task.index}`);
    checkbox.setAttribute('id', `check${task.index}`);
    // Set text input attributes
    textInput.classList.add('edit');
    textInput.setAttribute('type', 'text');
    textInput.setAttribute('name', `text${task.index}`);
    textInput.setAttribute('id', `text${task.index}`);

  • Here, I can remove this comment because I have added the styling I wanted in a different way.

    // li.style.boxShadow = '2px 2px 2px #444';

  • I am repeating the appendChild function a lot, and there should be a function to append multiple elements.

    li.appendChild(checkbox);
    li.appendChild(div);
    li.appendChild(textInput);
    li.appendChild(removeButton);
    li.appendChild(button);

  • I am repeating these functions for these elements.

    checkbox.setAttribute('name', `check${newIndex}`);
    checkbox.setAttribute('id', `check${newIndex}`);
    textInput.setAttribute('name', `text${newIndex}`);
    textInput.setAttribute('id', `text${newIndex}`);

Despite all, most of my code follows the best practices in my opinion.

@indigodavid
Copy link
Owner Author

indigodavid commented Jun 7, 2022

Two of the observations were addresses successfully. The other two observations require refactoring. Nevertheless, the refactoring of those functions is not keeping all the functionalities and it's making the code less readable. At the moment the code will remain because it is not affecting its readability or functionality. If I find a new way to implement these changes I will code them in a future feature.

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