From 95d2726392f3a3673e297eb06e17bea4efd204c5 Mon Sep 17 00:00:00 2001 From: katya-sn Date: Sun, 12 May 2024 15:03:21 +0300 Subject: [PATCH 1/2] solution --- README.md | 2 +- src/scripts/main.js | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d24722b5..80081e61 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://katya-sn.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 a765fdb1..d737cd59 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,23 @@ 'use strict'; -// write code here +const inputsCollection = document.querySelectorAll('input'); + +inputsCollection.forEach((input) => { + const inputName = input.getAttribute('name'); + const inputId = input.getAttribute('id'); + const capitalizedInputName = + inputName.charAt(0).toUpperCase() + inputName.slice(1); + + if (capitalizedInputName.includes('Name')) { + capitalizedInputName.replace('Name', ' Name'); + } + + const label = document.createElement('label'); + + label.setAttribute('class', 'field-label'); + label.setAttribute('for', inputId); + label.textContent = capitalizedInputName; + + input.setAttribute('placeholder', capitalizedInputName); + input.parentNode.appendChild(label); +}); From 929103b24ece6b54ddfc2ca92e163b49438b3b61 Mon Sep 17 00:00:00 2001 From: katya-sn Date: Mon, 13 May 2024 10:18:58 +0300 Subject: [PATCH 2/2] add space --- src/scripts/main.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index d737cd59..857d4b32 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -7,17 +7,15 @@ inputsCollection.forEach((input) => { const inputId = input.getAttribute('id'); const capitalizedInputName = inputName.charAt(0).toUpperCase() + inputName.slice(1); - - if (capitalizedInputName.includes('Name')) { - capitalizedInputName.replace('Name', ' Name'); - } + + const placeholder = capitalizedInputName.includes('Name') ? capitalizedInputName.replace('Name', ' Name') : capitalizedInputName; const label = document.createElement('label'); label.setAttribute('class', 'field-label'); label.setAttribute('for', inputId); - label.textContent = capitalizedInputName; + label.textContent = placeholder; - input.setAttribute('placeholder', capitalizedInputName); + input.setAttribute('placeholder', placeholder); input.parentNode.appendChild(label); });