Password generator solution | Typescript

Solution retrospective
Hello everyone, this is my first time implementing TypeScript in a project, how did I do? I would be very grateful for any recommendations on my code.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @HusseinSamy
Hello @jordanheve, 👋🏻
Awesome job on taking the first steps towards your dream!
I really like your submission and how you handled state of the strength meter through CSS (I didn't think in it that way when I was developing it). Though, I have some recommendations for you:
1.You can replace this code:
window.onload = () => { range.value = '10'; checkBoxes.forEach(checkbox => checkbox.checked = false); }
by setting the attributes directly in the html, they should look like this:
<input type="checkbox" name="uppercase" id="uppercase" checked />
2.Regarding some Typescript recommendations, you can do these:
- Define types for your variables:
let password: HTMLSpanElement = document.querySelector('.password-txt') as HTMLSpanElement
- Wrap this code inside it's own function and just call it when needed (clean code)
form?.addEventListener('submit', generatePassword) range?.addEventListener('input', updateTxt) copyButton?.addEventListener('click', copyEvent)
- Add type to the
checkboxChars
constant
type CheckboxChars = { uppercase: string; lowercase: string; numbers: string; symbols: string; }; const checkboxChars: CheckboxChars = { uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', lowercase: 'abcdefghijklmnopqrstuvwxyz', numbers: '0123456789', symbols: '!@#$%^&*()', };
Hope you find it useful!😇
Keep up the fantastic work, and happy coding! 🚀
Marked as helpful
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord