Skip to content

Solution#1813

Open
aholubko wants to merge 2 commits intomate-academy:masterfrom
aholubko:develop
Open

Solution#1813
aholubko wants to merge 2 commits intomate-academy:masterfrom
aholubko:develop

Conversation

@aholubko
Copy link

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.

Review Summary

I am approving your solution because it correctly implements the required behavior: labels are created from each input’s name, field-label is applied, placeholders are capitalized based on the name, and everything is done in a single loop attached to inputs inside the form. This covers the core checklist items like creating labels, setting for to the input’s id, using the name attribute as the source of text, and inserting the label into the input’s parent without wrapping the input.

A few improvements you might consider for robustness (not blockers):

  • Ensure the script runs after the DOM is ready (e.g., wrap your main logic in a DOMContentLoaded listener) so document.querySelectorAll('form input') always finds the inputs.
  • Skip inputs without a name (e.g., if (!fieldName) return;) so you don’t generate empty labels/placeholders.
  • If an input has no id, generate one from its name before setting label.htmlFor, and consider using label.classList.add('field-label') so you don’t overwrite any future classes.
    Overall, your solution meets the functional requirements well; these suggestions will just make it more robust and accessible in real-world scenarios.

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

Footnotes

  1. Rate AI review example

'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.

Selecting inputs immediately with document.querySelectorAll('form input') may run before the DOM is ready in some setups. Consider wrapping this logic in a DOMContentLoaded listener or otherwise ensuring the script runs after the form is parsed so the inputs are found reliably.

}

inputs.forEach((input) => {
const fieldName = input.getAttribute('name');

Choose a reason for hiding this comment

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

You rely on the name attribute (good), but if an input has no name this will produce an empty label and placeholder. Consider skipping inputs without a name (e.g. if (!fieldName) return;) so you only process inputs that meet the task's requirement to rely on name.


label.className = '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.

Setting for to input.id is correct, but if an input lacks an id you'll end up with an empty for attribute. Consider ensuring inputs have ids (or generate one from the name) so the label correctly targets the input.


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

label.className = 'field-label';

Choose a reason for hiding this comment

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

Assigning the class via label.className = 'field-label' works, but label.classList.add('field-label') is slightly safer (it preserves other classes if any are added later). This is a style/robustness suggestion rather than a functional requirement.

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