Skip to content

Update script.js #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -83,4 +89,4 @@ button.addEventListener("click", (e) => {
false,
document.getElementById("PasswordResult").select()
);
});
});