Skip to content

Commit

Permalink
function checkboxChecker refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoriM04 committed Jul 10, 2024
1 parent f74b1d5 commit 5b1938e
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,32 @@ const copySpantext = document.getElementById("copy-text");
const copyIcon = document.getElementById("copy-icon");
const passwords = document.getElementById("passwords");
const passStrength = document.getElementById("password-strength");

const includeLowercase = document.getElementById("lowercase");
const includeUppercase = document.getElementById("uppercase");
const includeNumbers = document.getElementById("numbers");
const includeSymbols = document.getElementById("symbols");
const allInputs = document.querySelectorAll(".input-container input");

// characters to be used in new passwords
let lowerCaseLetters = "abcdefghijklmnopqrstuvwxyz";
let upperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let numbers = "0123456789";
let symbols = "!@#$%&*()-_=+;.?";
let types = {
lowercase: "abcdefghijklmnopqrstuvwxyz",
uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
numbers: "0123456789",
symbols: "!@#$%&*()-_=+;.?",
};

// input checker
function checkboxChecker() {
let additions = "";
if (includeLowercase.checked) {
additions += lowerCaseLetters;
}
if (includeUppercase.checked) {
additions += upperCaseLetters;
}
if (includeNumbers.checked) {
additions += numbers;
}
if (includeSymbols.checked) {
additions += symbols;
let allValues = "";
for (let i = 0; i < allInputs.length; i += 1) {
if (allInputs[i].checked) {
for (const [key, value] of Object.entries(types)) {
if (allInputs[i].id === key) {
allValues += value;
}
}
}
}

if (additions === "") {
if (allValues === "") {
return "none";
} else {
return additions;
return allValues;
}
}

Expand Down

0 comments on commit 5b1938e

Please sign in to comment.