From 86c44a0546501228f5eaf3cef08f3176ece5ca8c Mon Sep 17 00:00:00 2001 From: kovaltar Date: Mon, 30 Sep 2024 02:06:20 +0300 Subject: [PATCH] Solution --- README.md | 2 +- src/scripts/main.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d24722b51..651cdf43c 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://kovaltar.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..778b45e4e 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,21 @@ 'use strict'; // write code here +const inputs = document.querySelectorAll('input'); + +function capitalize(str) { + const result = str; + + return result.charAt(0).toUpperCase() + result.slice(1); +} + +inputs.forEach((item, ind, arr) => { + const itemName = item.getAttribute('name'); + const itemLabel = document.createElement('label'); + + itemLabel.classList.add('field-label'); + itemLabel.setAttribute('for', item.id); + itemLabel.textContent = itemName.toUpperCase(); + item.setAttribute('placeholder', capitalize(itemName)); + item.before(itemLabel); +});