-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add solution #1429
base: master
Are you sure you want to change the base?
add solution #1429
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on implementing the task requirements! 🎉 Your code effectively creates and inserts labels for each input element, formats the text correctly, and adheres to the constraints of modifying only the main.js
file. While there are a few minor considerations regarding style handling, unique id
attributes, and compatibility with older browsers, these do not significantly impact the core functionality of your solution. Keep up the excellent work, and consider these suggestions for future improvements! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
src/scripts/main.js
Outdated
@@ -1,3 +1,19 @@ | |||
'use strict'; | |||
|
|||
// write code here | |||
let inputElement = document.querySelectorAll('form input') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The querySelectorAll
method returns a NodeList, which is not a true array. While the forEach
method is available on NodeLists in modern browsers, it might not be supported in older environments. Consider converting the NodeList to an array using Array.from()
if compatibility is a concern.
src/scripts/main.js
Outdated
|
||
let labelElement = document.createElement('label') | ||
labelElement.classList.add('field-label') | ||
labelElement.htmlFor = elem.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that each input element has a unique id
attribute. The htmlFor
property of the label must match the id
of the input element it labels. If any input elements lack an id
, this line will not work as intended.
src/scripts/main.js
Outdated
labelElement.htmlFor = elem.id | ||
labelElement.textContent = elem.name.replace(/(?<!\s)([A-Z])/g, ' $1').toUpperCase() || '' | ||
elem.placeholder = elem.name.replace(/(?<!\s)([A-Z])/g, ' $1') || '' | ||
elem.style = 'text-transform: capitalize;' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directly assigning a string to elem.style
will overwrite any existing inline styles. Consider using elem.style.textTransform = 'capitalize';
to avoid this issue.
DEMO LINK