I have a function called nameGenerator() that takes a variable, category, as a parameter.
Before this function is defined, I have two “pairs” of wordlist arrays: djentWords1 and djentWords2, and then hardcoreWords1 and hardcoreWords2.
nameGenerator() defines the following variables:
firstNumandsecondNumfirstWordandsecondWordbandName
The function generates two random numbers (firstNum and secondNum) between 0 and the length of either djentWords1 & djentWords2, or hardcoreWords1 & hardcoreWords2. My question is: can I pass nameGenerator() a parameter like “djent” or “hardcore”, and based on that parameter, have it use the appropriate array length to generate the random number? Here’s the function as-is:
//First category: djent
var djentWords1 = ["Aman", "Soul", "Cloud", "Calculate", "Pythagoran"];
var djentWords2 = ["NaaKi", "Circlet", "Cykul", "Consciousness", "Daaka"];
//Second category: hardcore
var hardcoreWords1 = ["SMASH", "RAGE", "LIFE", "THESE", "FIRST", "BRASS", "LAST"];
var hardcoreWords2 = ["FIST", "FIGHTER", "BREAKER", "SMASHER", "RUINER", "DAYS", "CHANCE"];
function nameGenerator (category){
//Randomize
var firstNum = Math.floor(Math.random() * categoryWords1.length); //categoryWords1 would either be djentWords1 or hardcoreWords1, based on the parameter passed to the function
var secondNum = Math.floor(Math.random() * categoryWords2.length); //categoryWords2 would either be djentWords2 or hardcoreWords2, based on the parameter passed to the function
var firstWord = categoryWords1[firstNum]; //firstWord = the word whose position corresponds to the first randomly-generated number
var secondWord = categoryWords2[secondNum]; //secondWord = the word whose position corresponds to the second randomly-generated number
var bandName = firstWord + secondWord;
}
Thanks in advance – and hopefully this wasn’t too confusing. All help is greatly appreciated.
Why not use an object (associative array)?