From 3b158216bf11e522b20aadd994c0924fb1289f1c Mon Sep 17 00:00:00 2001 From: yuliana111007-debug Date: Sun, 22 Feb 2026 20:06:17 +0200 Subject: [PATCH 1/3] add solution --- README.md | 2 +- src/scripts/main.js | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d24722b51..8bdc8260c 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://ybriukhovetska.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..109f27c22 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,28 @@ 'use strict'; -// write code here +const forms = document.querySelectorAll('form'); + +function capitalize(value) { + const word = value[0].toUpperCase() + value.slice(1); + + return word; +} + +for (const form of forms) { + const inputs = form.querySelectorAll('input'); + + for (const input of inputs) { + if (!input.id) { + input.id = input.name; + } + + const label = document.createElement('label'); + + label.classList.add('field-label'); + + label.htmlFor = input.id; + label.textContent = capitalize(input.name); + input.placeholder = capitalize(input.name); + input.parentNode.appendChild(label); + } +} From e50452bb9d5f0c165cdef1a9a3073305bc80ee6d Mon Sep 17 00:00:00 2001 From: yuliana111007-debug Date: Sun, 22 Feb 2026 20:32:19 +0200 Subject: [PATCH 2/3] add solution --- src/scripts/main.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 109f27c22..6e35c0dd5 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -3,26 +3,32 @@ const forms = document.querySelectorAll('form'); function capitalize(value) { - const word = value[0].toUpperCase() + value.slice(1); + if (!value) { + return ''; + } else { + const word = value[0].toUpperCase() + value.slice(1); - return word; + return word; + } } for (const form of forms) { const inputs = form.querySelectorAll('input'); for (const input of inputs) { - if (!input.id) { - input.id = input.name; - } + if (input.type === 'text' || input.type === 'password') { + if (!input.id && input.name) { + input.id = input.name; + } - const label = document.createElement('label'); + const label = document.createElement('label'); - label.classList.add('field-label'); + label.classList.add('field-label'); - label.htmlFor = input.id; - label.textContent = capitalize(input.name); - input.placeholder = capitalize(input.name); - input.parentNode.appendChild(label); + label.htmlFor = input.id; + label.textContent = capitalize(input.name); + input.placeholder = capitalize(input.name); + input.parentNode.insertBefore(label, input); + } } } From a6bac4569eb07c612ec9d4ac1fefbd7658e2e313 Mon Sep 17 00:00:00 2001 From: yuliana111007-debug Date: Sun, 22 Feb 2026 20:50:16 +0200 Subject: [PATCH 3/3] add solution --- src/scripts/main.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 6e35c0dd5..c718e10fb 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -16,19 +16,28 @@ for (const form of forms) { const inputs = form.querySelectorAll('input'); for (const input of inputs) { - if (input.type === 'text' || input.type === 'password') { - if (!input.id && input.name) { - input.id = input.name; - } + if ( + [ + 'submit', + 'button', + 'reset', + 'hidden', + 'image', + 'file', + 'checkbox', + 'radio', + ].includes(input.type) + ) { + continue; + } - const label = document.createElement('label'); + const label = document.createElement('label'); - label.classList.add('field-label'); + label.classList.add('field-label'); - label.htmlFor = input.id; - label.textContent = capitalize(input.name); - input.placeholder = capitalize(input.name); - input.parentNode.insertBefore(label, input); - } + label.htmlFor = input.id; + label.textContent = capitalize(input.name); + input.placeholder = capitalize(input.name); + input.parentNode.insertBefore(label, input); } }