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
25 changes: 25 additions & 0 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
'use strict';

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

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

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

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

label.classList.add('field-label');

label.setAttribute('for', input.id);
label.textContent = input.name || 'Field label';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Because you already return early when !input.name, the fallback || 'Field label' will never be used; you can simplify this to label.textContent = input.name if you want to keep the code minimal.


if (input.name) {
const capitalized = input.name[0].toUpperCase() + input.name.slice(1);

input.placeholder = capitalized;
}
input.parentElement.appendChild(label);
});
});
Loading