diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..3c88f3239 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,20 @@ 'use strict'; // write code here +const inputs = document.querySelectorAll('input'); + +inputs.forEach((input) => { + const label = document.createElement('label'); + + label.className = 'field-label'; + label.htmlFor = input.id; + + const displayName = input.name + .replace(/([A-Z])/g, ' $1') + .replace(/^./, (char) => char.toUpperCase()); + + label.textContent = displayName; + input.placeholder = displayName; + + input.parentElement.insertBefore(label, input); +});