From d5ff27c533184db1e22fa22f4f4efc31b4b0e03a Mon Sep 17 00:00:00 2001 From: naviailpach Date: Mon, 16 Feb 2026 18:24:32 +0200 Subject: [PATCH 1/2] add task solution --- src/scripts/main.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index a765fdb1d..77d3c3d64 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,3 +1,30 @@ 'use strict'; -// write code here +const inputs = document.querySelectorAll('input'); + +inputs.forEach((input) => { + if (!input.id) { + input.id = `${input.name}-input`; + } + + if (!input.name) { + return; + } + + if ( + input.type === 'submit' || + input.type === 'button' || + input.type === 'hidden' + ) { + return; + } + + const label = document.createElement('label'); + const labelText = input.name.charAt(0).toUpperCase() + input.name.slice(1); + + label.classList.add('field-label'); + label.htmlFor = input.id; + label.textContent = labelText; + input.placeholder = labelText; + input.parentNode.appendChild(label); +}); From 9340f9de44a11fbb64d87e97956faa4d23a245b8 Mon Sep 17 00:00:00 2001 From: naviailpach Date: Mon, 16 Feb 2026 18:43:42 +0200 Subject: [PATCH 2/2] complete task --- src/scripts/main.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/scripts/main.js b/src/scripts/main.js index 77d3c3d64..a25addc15 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,16 +1,16 @@ 'use strict'; -const inputs = document.querySelectorAll('input'); +const inputs = document.querySelectorAll('form input'); inputs.forEach((input) => { - if (!input.id) { - input.id = `${input.name}-input`; - } - if (!input.name) { return; } + if (!input.id) { + input.id = `${input.name}-input`; + } + if ( input.type === 'submit' || input.type === 'button' || @@ -26,5 +26,5 @@ inputs.forEach((input) => { label.htmlFor = input.id; label.textContent = labelText; input.placeholder = labelText; - input.parentNode.appendChild(label); + input.parentNode.insertBefore(label, input); });