From 9ccc2c99a6f660ec5e0f7d48fe83b5c0cc2a9737 Mon Sep 17 00:00:00 2001 From: Ferens Sofia Date: Fri, 6 Feb 2026 21:51:19 +0200 Subject: [PATCH] add task solution --- src/scripts/main.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..b9b12c88f 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,29 @@ 'use strict'; -// write code here +// Select all forms on the page +const forms = document.querySelectorAll('form'); + +forms.forEach((form) => { + const inputs = form.querySelectorAll('input'); + + inputs.forEach((input) => { + // Create label + const label = document.createElement('label'); + + label.className = 'field-label'; + label.setAttribute('for', input.id); + + // Capitalize input name for label text + const labelText = input.name + ? input.name.charAt(0).toUpperCase() + input.name.slice(1) + : 'Field'; + + label.textContent = labelText; + + // Set placeholder + input.placeholder = labelText; + + // Insert label before input + input.parentElement.insertBefore(label, input); + }); +});