![]() When the loop is finished, display the password in the password textbox. ![]() In each iteration of the loop, randomly select one of the characters from the chars constant and concatenate it to the password variable. If the number entered by the user is valid, code a for loop that iterates that number of times. If it isn't, display an alert dialog box with this message: "Please enter a valid number”. In the handler for the Get Password button, get the value entered by the user and make sure it's a number. Password Generator Generate a strong password Number of characters: Password: īody ) // end ready()ģ. Iterate Over Password Length, Adding Generated Characters Let’s now iterate over a loop in JavaScript, based on the password length configured, and use our randomly generated characters. In the handler for the Get Password button, get the value entered by the user and make sure it's a number. Using JavaScript’s Math.floor () and Math.random () we can be sure we return unique characters each time. The handler for the Clear button resets the text boxes and moves the focus to the first text box 3. The handler for the Get Password button clears the password text box and has a constant named chars that contains some characters. Also, note that the ready event handler contains the handler for the click event of the Get Password button and the handler for the click event of the Clear button. In the JavaScript file, note the getRandomNumber() function. Open the application in this folder: exercises_extra ch12\password 2. Generate a strong password Number of characters: 10 Password: ZAUWAOY! Get Password Clear 1. 29 Extra exercises for Murach's JavaScript and jQuery (4" Edition) Extra 12-3 Develop a password generator In this exercise, you'll develop an application that generates strong passwords of the length entered by the user.
0 Comments
Leave a Reply. |