I am having a hard time figuring how to use "click-to-copy" function in order to copy the password1 and password2 variables from the last function. So far i thought of rendering the random password inside <buttons> in order to add an onclick function to it, but i have no idea how i can take the random password generated by generatePassword() and pass it to copyToClipboard(1). I am adding my code in a notepad as it is too long to post it here
#Module 3 - Solo project question - password generator
1 messages · Page 1 of 1 (latest)
Can you post a link to your scrim?
I think that this is a Scrimba problem - see the error message in the REAL console:
Please try this one: https://scrimba.com/scrim/c8wk3nTK
as an alternative i have pasted the script in the attached text file as I am using VSC for solo projects
Ok, I've downloaded to my VSC...
Make the following changes: Add the event to your buttons onClick handlers:
<button id="rectangle1" onclick="copyToClipboard1(event)"></button>
<button id="rectangle2" onclick="copyToClipboard2(event)"></button>
Get the content of the button clicked:
function copyToClipboard1(event) {
// navigator.clipboard.writeText('muie');
navigator.clipboard.writeText(event.target.textContent);
}
There are other ways to do this but this will work given your current structure...
Hi Bill, i have just finished m3 and i have a little more understanding of function parameters, but i still cant figure out what is event doing in this code
The event is supplied automatically by the engine when you click the button. You don't need to use it but it's available for you if you do need it.
The nice thing about the event object is that it gives you a bunch of information about what occurred - for example it tells your WHICH object was clicked (event.target) which is one way of sharing event handlers... In fact in your case you could have a single copyToClipboard() function... That's basically how I wrote it above so you know which password to copy by virtue of the event.target and then you extract the textContent from that...