Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
'use strict';

// write code here
let k = document.querySelectorAll('form .field .field-text');

let m = Array.from(k);

m.forEach((el) => {
let k = el.getAttribute('name');

Check failure on line 8 in src/scripts/main.js

View workflow job for this annotation

GitHub Actions / build (20.x)

'k' is already declared in the upper scope on line 3 column 7
let p = el.getAttribute('id');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this code works, using short, non-descriptive variable names like k, m, and p makes the code hard to understand. It's a best practice to use meaningful names that describe what the variable holds, for example, inputElements, inputName, or inputId.

Additionally, reusing the variable name k inside the loop (lines 3 and 8) is a practice called 'shadowing' and can be confusing. It's better to use a new, distinct variable name for the input's name attribute inside the loop.


k = k[0].toUpperCase() + k.slice(1);
el.setAttribute('placeholder', k);
const label = document.createElement('label');
label.className = 'field-label';
label.htmlFor = p;
label.textContent = k;

el.before(label);
});
Loading