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

add task solution #1309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add task solution #1309

wants to merge 1 commit into from

Conversation

Mykolyan
Copy link

@Mykolyan Mykolyan commented Nov 6, 2024

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on implementing the script to dynamically create and insert labels for form inputs! 🎉 Your code meets the task requirements effectively. However, consider adding checks to ensure that each input has a name and id attribute to avoid potential errors. This will make your code more robust and reliable. Keep up the good work and happy coding! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

@@ -1,3 +1,18 @@
'use strict';

// write code here
const inputs = document.querySelectorAll('form input');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the form inputs have unique IDs and names, as the script relies on these attributes to set the 'for' attribute of the label and to generate the label text.

const label = document.createElement('label');

label.classList.add('field-label');
label.setAttribute('for', input.id);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any input element lacks an 'id' attribute, the 'for' attribute of the label will not be set correctly. Consider adding a check to ensure that the input has an 'id' before setting the 'for' attribute.

label.classList.add('field-label');
label.setAttribute('for', input.id);

const labelText = input.name.charAt(0).toUpperCase() + input.name.slice(1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any input element lacks a 'name' attribute, this line will cause an error. Consider adding a check to ensure that the input has a 'name' before attempting to access it.

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

Successfully merging this pull request may close these issues.

2 participants