Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
'use strict';

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

forms.forEach((form) => {
const inputs = form.querySelectorAll('input');

inputs.forEach((item) => {
if (item.tagName === 'INPUT') {
const idInput = item.getAttribute('id');
const nameInput = item.getAttribute('name');
const label = document.createElement('label');

const capitalize = nameInput[0].toLocaleUpperCase() + nameInput.slice(1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This line assumes nameInput exists and has at least one character. If an input lacks a name attribute, nameInput[0] will throw. Add a guard (e.g., skip this input or provide a fallback) before using nameInput[0].


label.classList.add('field-label');
item.setAttribute('placeholder', capitalize);
label.setAttribute('for', idInput);
label.textContent = nameInput;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You set label.textContent to the raw nameInput (lowercase). The task expects the label text to be based on the input name; for consistency with the placeholder you should use the capitalized value (capitalize) instead of nameInput.

item.before(label);
}
});
});
Loading