Let me know if any of this is confusing and I’ll try to clarfiy!I’d like to make a semi-random name generator. The names are made from three parts: [first] of the [second] [third], like [Flash] of the [sapphire] [sky]. What makes the names complicated is that they need to have at least one nature-related word in them in any of the three parts, like Beach of Summer’s Joy (“Beach” is the nature word, in the first part), Dedication of the Maple’s Colors (“Maple,” in the second), or Anger of the Rolling Ocean (“Ocean” here, in the third part). Thanks to online-generator.com, I was able to make a completely random generator without a problem; that generator pulled words from three sets and pieced them together. But, being random, it created names that didn’t follow the rule of having a nature term in there. Duh.After playing around with a few generators, I think I’ve figured out a way to accomplish this. I have four variable sets: one for each part of the name, and then a fourth set that will include the nature terms. And then here’s where I get stuck. I can’t come up with and/or borrow code that will instruct the generator to swap in the fourth variable set for one of the three other sets.So my question is, how do I do that? Which is linked to other questions: Is this possible? Am I coding it correctly or do I need a different approach? I’m hoping that someone can at least point me in the right direction! Again, please let me know if this question or post doesn’t make sense.Here’s my current and incomplete code, minus the vast majority of terms in the variable sets (and the style sheets and whatnot, to save space):
<html><head> <script type="text/javascript"> function generator(){ var wordlist1 = ["Abhorrence","Acclamation","Adoration","Adornment",,"Artist","Ash","Ashes","Attacker","Aurora","Yearning","Zenith","Zephyr"]; var wordlist2 = ["of Mythic","of the Abhorrent","of the Accursed","of the Adorned","of the Amber","of the Amber","of the Amethyst","of the Ancient","of the Approaching","of the Aquatic","of the Wretched","of the Xanthic","of the Yellow"];var wordlist3 = ["Adornment","Air","Alignment","Amber","Asylum","Attacker","Aurora","Autumn","Awe","Bands","Basilisk","Battle","Beach","Bedrock","Blaze","Blood","Blossom","Wound","Wraith","Wreath","Zenith","Zephyr"]var wordlist4 = ["Amber","Aurora","Autumn","Beach","Bedrock","Blossom","Blossoms","Bough","Branch","Breeze","Breezes","Briar","Brine","Charcoal"] // Random numbers are made var randomNumber1 = parseInt(Math.random() * wordlist1.length); var randomNumber2 = parseInt(Math.random() * wordlist2.length); var randomNumber3 = parseInt(Math.random() * wordlist3.length); var randomNumber4 = parseInt(Math.random() * wordlist4.length); var name = wordlist1[randomNumber1] + " " + wordlist2[randomNumber2] + " " + wordlist3[randomNumber3]; //alert(name); //Remove first to slashes to alert the name //If there's already a name it is removed if(document.getElementById("result")){ document.getElementById("placeholder").removeChild(document.getElementById("result")); } // A div element is created to show the generated name. The Name is added as a textnode. Textnode is added to the placeholder. var element = document.createElement("div"); element.setAttribute("id", "result"); element.appendChild(document.createTextNode(name)); document.getElementById("placeholder").appendChild(element); } </script>
Thank you! I’m new to coding, so please excuse my ignorance. This was supposed to be a fun test for myself and a little gift for a friend, but I had no idea how complicated it’d be for me.