Alright, I'm trying to keep brevity here but I'm not sure where things go wrong. So I have this program for generating random names. There's an HTML interface, with check boxes for three cultures (anglo, french, and spanish), as first names and last names. So if the user wanted to generate a name where the first name was anglo but the last name was anglo or spanish sounding (like Jason Gomez or Jason Smith), he could by checking the appropriate boxes.
The program is supposed to loop through the input elements, and check which ones are checked, then use that information to add a cultural array to an array of potential names.
This seems to chug along smoothly until the very end. What's the deal?
f_anglo = ["Stacey", "Jennifer", "Kelsey"];
f_french = ["Marie", "Claire", "Elise"];
f_spanish = ["Carmen", "Angelita"];
m_anglo = ["John", "Mike", "Jason"];
m_french = ["Pierre", "Jean", "Didier"];
m_spanish = ["Diego", "Jorge", "Jose"];
s_anglo = ["Smith", "Jones", "Jackson"];
s_french = ["Dupuis", "Trichet", "Brissont"];
s_spanish = ["Ramirez", "Ruiz", "Mendez"];
function genName(){
let firstNameBoxes = document.getElementsByClassName("firstName");
let surnameBoxes = document.getElementsByClassName("surname");
if($("#gender").val() == "male") {
//empty arrays that will be filled with cultural arrays based on what boxes are checked.
let potentialFirstNames = [];
let potentialSurnames = [];
for(let x in firstNameBoxes) {
//this runs through the boxes under "Last name:" and checks which ones are checked
//depending on which are checked, it will add them to array of potential names
if(firstNameBoxes[x].checked) {
switch(firstNameBoxes[x].value) {
case "anglo":
potentialFirstNames.concat(m_anglo);
break;
case "french":
potentialFirstNames.concat(m_french);
break;
case "spanish":
potentialFirstNames.concat(m_spanish);
break;
}
}
}
for(let x in surnameBoxes) {
//same thing but with last names
if(surnameBoxes[x].checked) {
console.log("checked")
//this console.log fires the appropriate amount of times.
console.log(surnameBoxes[x].value);
//these all show the proper values
switch(surnameBoxes[x].value) {
case "anglo":
potentialSurnames.concat(s_anglo);
break;
case "french":
potentialSurnames.concat(s_french);
break;
case "spanish":
potentialSurnames.concat(s_spanish);
break;
}
}
}
//these never fill up
console.log(potentialFirstNames);
console.log(potentialSurnames);