Hola @JJorgeMS13,
I love your solution! π₯³π₯³π₯³
The only thing, I would change is to show a confirmation message "Copied!" next to the copy icon or in the password field instead of showing an alert. This will help enhance the user experience.
Just as an example, this is how I solved it:
// COPY PASSWORD FUNCTION
copyIcon.addEventListener("click", copyPassword);
function copyPassword() {
const passwordText = generatedPassword.textContent;
console.log(passwordText);
if (passwordText === "P4$5W0rD!" || passwordText === "Tick at least 1 box") {
return;
}
navigator.clipboard
.writeText(passwordText)
.then(() => {
const originalText = generatedPassword.textContent;
generatedPassword.textContent = "Copied!";
generatedPassword.classList.add("copied");
setTimeout(() => {
generatedPassword.textContent = originalText;
generatedPassword.classList.remove("copied");
}, 2000);
})
.catch((err) => {
console.log("Failed to copy: ", err);
});
}
Happy Coding!