From cdffcf79655bf05d48ca97e873395f4b31625224 Mon Sep 17 00:00:00 2001 From: Infinity <85234537+guptaanant682@users.noreply.github.com> Date: Sat, 18 Nov 2023 01:14:13 +0530 Subject: [PATCH] Update script.js added some more detailed comments --- script.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/script.js b/script.js index 66597ea..400c35d 100644 --- a/script.js +++ b/script.js @@ -5,24 +5,30 @@ Math.floor() function returns the largest integer less than or equal to a given For generating a random uppercase lowercase text random numbers symbols we use Charcode http://stevehardie.com/2009/09/character-code-list-char-code/ */ + +// getRandomLower(): This function returns a random lowercase letter using the Unicode character code. function getRandomLower() { return String.fromCharCode(Math.floor(Math.random() * 26) + 97); } +// getRandomUpper(): This function returns a random uppercase letter using the Unicode character code. function getRandomUpper() { return String.fromCharCode(Math.floor(Math.random() * 26) + 65); } +// getRandomNumber(): This function returns a random number using the Unicode character code. function getRandomNumber() { return +String.fromCharCode(Math.floor(Math.random() * 10) + 48); } +// getRandomSymbol(): This function returns a random symbol from a predefined list of symbols. function getRandomSymbol() { const symbols = "!@#$%^&*(){}[]=<>/,."; return symbols[Math.floor(Math.random() * symbols.length)]; } // adding a all functions into a object called randomFunc +// An object randomFunc is created to store references to the above functions. const randomFunc = { lower: getRandomLower, upper: getRandomUpper, @@ -49,7 +55,7 @@ generate.addEventListener("click", () => { // console.log(hasLower, hasUpper, hasNumber, hasSymbol); }); -// function for generating random password +// The generatePassword() function takes the user's selected criteria and generates a random password based on those criteria. function generatePassword(lower, upper, number, symbol, length) { let generatedPassword = ""; const typesCount = lower + upper + number + symbol; @@ -83,4 +89,4 @@ button.addEventListener("click", (e) => { false, document.getElementById("PasswordResult").select() ); -}); \ No newline at end of file +});