From 60de547ec5cfe574dd86192f44111c4569d42eea Mon Sep 17 00:00:00 2001 From: Denys Boiko Date: Sat, 13 Jun 2026 22:04:42 +0200 Subject: [PATCH 1/2] Solution --- src/scripts/main.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..99eafaa41 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,27 @@ 'use strict'; -// write code here +const formInputs = document.querySelectorAll('input'); + +function capitalize(text) { + if (!text) { + return ''; + } + + return text.charAt(0).toUpperCase() + text.slice(1); +} + +formInputs.forEach((input) => { + const nameValue = input.name; + const labelText = nameValue.toUpperCase(); + const placeholderText = capitalize(nameValue); + + input.placeholder = placeholderText; + + const label = document.createElement('label'); + + label.classList.add('field-label'); + label.setAttribute('for', input.id); + label.textContent = labelText; + + input.parentElement.prepend(label); +}); From 8eb8fe4f3184204dd1bf33bef25d44e18e26b8e8 Mon Sep 17 00:00:00 2001 From: Denys Boiko Date: Sat, 13 Jun 2026 22:12:34 +0200 Subject: [PATCH 2/2] Fix --- src/scripts/main.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 99eafaa41..451944ac5 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,6 +1,6 @@ 'use strict'; -const formInputs = document.querySelectorAll('input'); +const formInputs = document.querySelectorAll('form input'); function capitalize(text) { if (!text) { @@ -12,16 +12,15 @@ function capitalize(text) { formInputs.forEach((input) => { const nameValue = input.name; - const labelText = nameValue.toUpperCase(); - const placeholderText = capitalize(nameValue); + const formattedText = capitalize(nameValue); - input.placeholder = placeholderText; + input.placeholder = formattedText; const label = document.createElement('label'); label.classList.add('field-label'); label.setAttribute('for', input.id); - label.textContent = labelText; + label.textContent = formattedText; input.parentElement.prepend(label); });