I am making a random password generator. The generating part itself is working, but I don't know how to convert the chars to phonetic. I mean, I got the function, but I don't know how to use it. I need to check every character of the password and call function convertToPhonetic
with character being parameter for each character. I think I need to use a for
loop, but since I just started I don't know how to properly use for loops. I tried searching it up on google, but found nothing.
JS:
function gen() {
var symbol = document.getElementById("symbolsCB");
var number = document.getElementById("numbersCB");
var upper = document.getElementById("uppersCB");
var length = document.getElementById("myRange");
var op = document.getElementById("outputBox");
var strBox = document.getElementById("strengthBox");
op.value = '';
var list=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
if (symbol.checked == true) {
var symbols = ["?", "!", "#", "$", "%", "*", "(", ")", "[", "]", "{", "}", "<", ">"];
symbols.push.apply(list, symbols);
}
if (number.checked == true) {
var numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
numbers.push.apply(list, numbers);
}
if (upper.checked == true) {
var uppers = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
uppers.push.apply(list, uppers);
}
for (var i = 0; i < length.value; i++) {
let char = list[Math.floor(Math.random() * list.length)];
op.value = op.value + char;
}
const password = op.value; /* for future */
var pwl = password.length; /* use */
if (length.value < 10){
strBox.value = "Weak password";
document.body.style.background = "#bf0a33";
}
if (length.value >= 10){
strBox.value = "Strong password";
document.body.style.background = "#20b422";
}
function convertToPhonetic(character){
if(character=="a"){return" apple";}if(character=="A"){return" APPLE";}if(character=="b"){return" bestbuy";}if(character=="B"){return" BESTBUY";}if(character=="c"){return" coffee";}if(character=="C"){return" COFFEE";}if(character=="d"){return" drip";}if(character=="D"){return" DRIP";}if(character=="e"){return" egg";}if(character=="E"){return" EGG";}if(character=="f"){return" fruit";}if(character=="F"){return" FRUIT";}if(character=="g"){return" golf";}if(character=="G"){return" GOLF";}if(character=="h"){return" HULU";}if(character=="H"){return" HULU";}if(character=="i"){return" igloo";}if(character=="I"){return" IGLOO";}if(character=="j"){return" jar";}if(character=="J"){return" JAR";}if(character=="k"){return" koala";}if(character=="K"){return" KOALA";}if(character=="l"){return" lion";}if(character=="L"){return" LION";}if(character=="m"){return" monkey";}if(character=="M"){return" MONKEY";}if(character=="n"){return" nut";}if(character=="N"){return" NUT";}if(character=="o"){return" octopus";}if(character=="O"){return" OCTOPUS";}if(character=="p"){return" person";}if(character=="P"){return" PERSON";}if(character=="q"){return" queen";}if(character=="Q"){return" QUEEN";}if(character=="r"){return" rope";}if(character=="R"){return" ROPE";}if(character=="s"){return" skype";}if(character=="S"){return" SKYPE";}if(character=="t"){return" tokyo";}if(character=="T"){return" TOKYO";}if(character=="u"){return" usa";}if(character=="U"){return" USA";}if(character=="v"){return" violin";}if(character=="V"){return" VIOLIN";}if(character=="w"){return" walmart";}if(character=="W"){return" WALMART";}if(character=="x"){return" xbox";}if(character=="X"){return" XBOX";}if(character=="y"){return" yelp";}if(character=="Y"){return" YELP";}if(character=="z"){return" zip";}if(character=="Z"){return" ZIP";}
else{return " " + character;}
}
console.log(password + ", length => " + pwl);
function showPhonetic(){
}
}
var slider = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider.value;
slider.oninput = function() {
gen();
output.innerHTML = this.value;
};
window.onload = function() {
gen();
};
HTML:
<div class="page" id="page">
<div>
<button onclick="gen()"> ↻ </button>
<input type="text" id="outputBox" disabled="disabled">
</div>
<input type="text" id="strengthBox" disabled="disabled">
<div class="slidecontainer">
<p id="len">Length: <span id="demo"></span></p>
<input type="range" min="4" max="40" value="16" class="slider" id="myRange">
</div>
<input type="checkbox" name="numbers" id="numbersCB" class="cb" onclick="gen()" checked>
<label for="numbers">Include Numbers </label>
<input type="checkbox" name="uppers" id="uppersCB" class="cb" onclick="gen()" checked>
<label for="uppers">Include Uppercase Letters </label>
<input type="checkbox" name="symbols" id="symbolsCB" class="cb" onclick="gen()" checked>
<label for="symbols">Include Symbols </label>
<span> Remember your password: </span><input id="phoneticPronounciation">
</div>
Please also tell me what the problem is and not just paste a bunch of code.