diff --git a/README.md b/README.md index d24722b5..f56b508d 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://EgorMamtsev.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..dacf1f7b 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,28 @@ 'use strict'; -// write code here +const inputsCollection = [...document.querySelectorAll('input')]; + +for (let i = 0; i < inputsCollection.length; i++) { + const label = document.createElement('label'); + let currentValue = ''; + + if ( + inputsCollection[i].getAttribute('name') === 'firstName' || + inputsCollection[i].getAttribute('name') === 'lastName' + ) { + currentValue = inputsCollection[i] + .getAttribute('name') + .replace(/([A-Z])/g, ' $1'); + } else { + currentValue = inputsCollection[i].getAttribute('name'); + } + + label.textContent = currentValue.toUpperCase(); + + const parented = inputsCollection[i].parentElement; + + parented.prepend(label); + + inputsCollection[i].placeholder = + currentValue.charAt(0).toUpperCase() + currentValue.slice(1); +}