Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-marcovych committed Mar 3, 2025
1 parent c5d4dde commit c2382f5
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
'use strict';

// write code here
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('input').forEach((input) => {
const inputParent = input.parentNode;

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

label.classList.add('field-label');
label.setAttribute('for', input.id);
label.textContent = formatLabelText(input.name);

input.placeholder = formatLabelText(input.name);

inputParent.insertBefore(label, input);
});
});

function formatLabelText(text) {
const labels = {
firstName: 'First Name',
lastName: 'Last Name',
};

return labels[text] || text.charAt(0).toUpperCase() + text.slice(1);
}

0 comments on commit c2382f5

Please sign in to comment.