Skip to content
Open
Changes from all commits
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
29 changes: 28 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
'use strict';

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

inputs.forEach((input) => {
if (!input.name) {
return;
}

if (!input.id) {
input.id = `${input.name}-input`;

Choose a reason for hiding this comment

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

You assign input.id = ${input.name}-input`` before checking the input type. Because you return for submit, `button`, and `hidden` inputs later (lines 14–18), those inputs may receive an id even though no label/placeholder is created. Consider moving the type check (lines 14–18) above the id assignment or only setting `id` after confirming the input will be processed.

}

if (
input.type === 'submit' ||
input.type === 'button' ||
input.type === 'hidden'
) {
return;
}

const label = document.createElement('label');
const labelText = input.name.charAt(0).toUpperCase() + input.name.slice(1);

label.classList.add('field-label');
label.htmlFor = input.id;
label.textContent = labelText;
input.placeholder = labelText;
input.parentNode.insertBefore(label, input);
});
Loading