From 6fde8571b0ae35c4cfd00419d6164da278e8d29a Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 5 May 2026 03:32:49 +0300 Subject: [PATCH 1/2] add task solution --- README.md | 2 +- src/scripts/main.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d24722b51..a84b632f5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ 1. Replace `` with your Github username in the link - - [DEMO LINK](https://.github.io/js_task_fix_form_DOM/) + - [DEMO LINK](https://Roma-Yamshchikov.github.io/js_task_fix_form_DOM/) 2. Follow [this instructions](https://mate-academy.github.io/layout_task-guideline/) - Run `npm run test` command to test your code; - Run `npm run test:only -- -n` to run fast test ignoring linter; diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..b8564d006 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,19 @@ 'use strict'; // write code here +const input = [...document.querySelectorAll('input')]; + +input.forEach((item) => { + const label = document.createElement('label'); + + const namePlaceholder = + item.getAttribute('name')[0].toUpperCase() + + item.getAttribute('name').slice(1); + + item.setAttribute('placeholder', namePlaceholder); + + label.classList.add('field-label'); + label.setAttribute('for', item.id); + label.textContent = item.getAttribute('name'); + item.before(label); +}); From 0ac14e00eaf194d4021da98179a2d6fdbca145fe Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 5 May 2026 15:33:41 +0300 Subject: [PATCH 2/2] fixed task main.js --- src/scripts/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index b8564d006..cff2cf13d 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,7 +1,7 @@ 'use strict'; // write code here -const input = [...document.querySelectorAll('input')]; +const input = [...document.querySelectorAll('form input')]; input.forEach((item) => { const label = document.createElement('label'); @@ -15,5 +15,5 @@ input.forEach((item) => { label.classList.add('field-label'); label.setAttribute('for', item.id); label.textContent = item.getAttribute('name'); - item.before(label); + item.parentElement.appendChild(label); });