Skip to content

Commit

Permalink
add task solution
Browse files Browse the repository at this point in the history
  • Loading branch information
viktoriiadereza committed Sep 23, 2024
1 parent 5f0eefc commit 12f3648
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ const fields = document.querySelectorAll('.field');
function createLabelAndPlaceholder(input) {
const label = document.createElement('label');

const spaceSeparatedString = input.name.replace(/([A-Z])/g, ' $1').trim();

const capitalizedText =
spaceSeparatedString.charAt(0).toUpperCase() +
spaceSeparatedString.slice(1);

label.classList.add('field-label');
label.textContent = input.name.charAt(0).toUpperCase() + input.name.slice(1);
label.textContent = capitalizedText;
label.setAttribute('for', input.id);

input.placeholder = input.name.charAt(0).toUpperCase() + input.name.slice(1);
input.placeholder = capitalizedText;

input.parentNode.insertBefore(label, input);
}
Expand Down

0 comments on commit 12f3648

Please sign in to comment.