0
<!DOCTYPE html>
<html>
<head>
    <title> Password Generator </title>
    </head>
    <body>
    <button onclick="PasswordGen()">Generate Password</button>
    <script>
        const emotion = ["Sad", "Happy", "Mad", "Miserable", "Shy", "Cheerful", "Angry", "Amazing", "Anxious", "Scared", "Bashful", "Brave", "Tired", "Excited", "Cautious", "Bubbly"];
        const noun = ["Actors", "Queens", "Kings", "Princes", "Princesses", "Cows", "Pigs", "Chickens", "Dogs", "Cats", "Clouds", "Fathers", "Mothers", "Brothers", "Sisters", "Uncles", "Aunties", "Zebras", "Fish", "Elephants"];
        const verb = ["Jump", "Play", "Run", "Sprint", "Walk", "Throw", "Fall", "Fly", "Search", "Train", "Grow", "Smell",  "Eat", "Whistle", "Write", "Read", "Swim", "Win", "Plan", "Scream", "Sleep"];
        function RandomNum(array) 
        {
            return Math.ceil(Math.random() * array.length-1);
        }
        num1 = Math.ceil(Math.random() * 9);
        function PasswordGen()
        {
            document.write(num1 + emotion[RandomNum(emotion)] + noun[RandomNum(noun)] + verb[RandomNum(verb)]);
        }
    </script>
    
    </body>
    </html>

So im doing some basic coding for tafe and it's been easy so far but im not too good at js and HTML, i've made this button setup put i think it's orinting over the button with the password. I want the button to be there after the password gets printed to re-generate the password.

  • 1
    You're clearing the DOM when you use `document.write()` after the page has loaded. – Barmar Aug 17 '22 at 03:18
  • 2
    don't use `document.write` unless you understand it - and even then, it should (hardly) ever be used – Jaromanda X Aug 17 '22 at 03:18
  • 1
    With document.write() you are overriding the whole dom. You simply declare a p tag in your body and use its Id to change its innertext. – blaze2004 Aug 17 '22 at 03:21

0 Answers0