From 22eecd576cfc7e89a15ec6853708e872936fc512 Mon Sep 17 00:00:00 2001 From: w11ue Date: Tue, 30 Jun 2026 23:28:23 +0200 Subject: [PATCH 1/4] add task solution --- src/scripts/main.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..4c993605f 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,30 @@ 'use strict'; // write code here +document.querySelectorAll('form').forEach((form) => { + form.querySelectorAll('input').forEach((input) => { + const label = document.createElement('label'); + + label.className = 'field-label'; + label.setAttribute('for', input.id); + + // Отримуємо назву поля без конфлікту з глобальним name + const fieldName = input.name; + + // Форматуємо текст: firstName -> First Name + let displayName = fieldName.replace(/([A-Z])/g, ' $1').trim(); + + displayName = displayName.charAt(0).toUpperCase() + displayName.slice(1); + + // Для пароля використовуємо стандартну назву + if (input.type === 'password') { + displayName = 'Password'; + } + + label.textContent = displayName; + input.placeholder = displayName; + + // Вставляємо мітку перед полем + input.parentNode.insertBefore(label, input); + }); +}); From b56a939c9a929d55851827b60e17f32e395f4cc1 Mon Sep 17 00:00:00 2001 From: w11ue Date: Wed, 1 Jul 2026 21:54:07 +0200 Subject: [PATCH 2/4] add task solution --- src/scripts/main.js | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 4c993605f..20e42e50e 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,30 +1,24 @@ 'use strict'; // write code here -document.querySelectorAll('form').forEach((form) => { - form.querySelectorAll('input').forEach((input) => { - const label = document.createElement('label'); +const form = document.querySelector('form'); +const inputs = form.querySelectorAll('input'); - label.className = 'field-label'; - label.setAttribute('for', input.id); +inputs.forEach((input) => { + const label = document.createElement('label'); - // Отримуємо назву поля без конфлікту з глобальним name - const fieldName = input.name; + label.className = 'field-label'; + label.setAttribute('for', input.id); - // Форматуємо текст: firstName -> First Name - let displayName = fieldName.replace(/([A-Z])/g, ' $1').trim(); + const fieldName = input.name; + let displayName = fieldName.charAt(0).toUpperCase() + fieldName.slice(1); - displayName = displayName.charAt(0).toUpperCase() + displayName.slice(1); + if (input.type === 'password') { + displayName = 'Password'; + } - // Для пароля використовуємо стандартну назву - if (input.type === 'password') { - displayName = 'Password'; - } + label.textContent = displayName; + input.placeholder = displayName; - label.textContent = displayName; - input.placeholder = displayName; - - // Вставляємо мітку перед полем - input.parentNode.insertBefore(label, input); - }); + input.parentElement.insertBefore(label, input); }); From 2aeaac70dcd1f1b10b709edb170fdf162cfa97d9 Mon Sep 17 00:00:00 2001 From: w11ue Date: Thu, 2 Jul 2026 23:32:33 +0200 Subject: [PATCH 3/4] add task solution --- src/scripts/main.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 20e42e50e..19a7b9b57 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -11,11 +11,9 @@ inputs.forEach((input) => { label.setAttribute('for', input.id); const fieldName = input.name; - let displayName = fieldName.charAt(0).toUpperCase() + fieldName.slice(1); + let displayName = fieldName.replace(/([A-Z])/g, ' $1').trim(); - if (input.type === 'password') { - displayName = 'Password'; - } + displayName = displayName.charAt(0).toUpperCase() + displayName.slice(1); label.textContent = displayName; input.placeholder = displayName; From d0ac875c97127d136b4c877308dcd1ac1b3db20e Mon Sep 17 00:00:00 2001 From: w11ue Date: Fri, 3 Jul 2026 23:43:10 +0200 Subject: [PATCH 4/4] add task solution --- src/scripts/main.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 19a7b9b57..3c88f3239 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,19 +1,17 @@ 'use strict'; // write code here -const form = document.querySelector('form'); -const inputs = form.querySelectorAll('input'); +const inputs = document.querySelectorAll('input'); inputs.forEach((input) => { const label = document.createElement('label'); label.className = 'field-label'; - label.setAttribute('for', input.id); + label.htmlFor = input.id; - const fieldName = input.name; - let displayName = fieldName.replace(/([A-Z])/g, ' $1').trim(); - - displayName = displayName.charAt(0).toUpperCase() + displayName.slice(1); + const displayName = input.name + .replace(/([A-Z])/g, ' $1') + .replace(/^./, (char) => char.toUpperCase()); label.textContent = displayName; input.placeholder = displayName;