Randomizer Using Javascript

<html>
<body>

<script type="text/javascript">
function displaymessage()
{
   
var colors = ["agate", "alexandrite", "chrysoberyl", "aquamarine", "beryl", "chrysocolla", "diamond", "emerald", "feldspar", "garnet", "hermatite", "jade", "jasper", "kunzite", "lapis lazuli", "jadeite", "nephrite", "malachite", "obsidian", "peridot", "opal", "pyrite", "quartz", "agate", "amethyst", "citrine", "chalcedony", "onyx", "tiger's-eye", "ruby", "sapphire", "spinel", "sugilite", "tanzanite", "zoisite", "topaz", "turqoise", "tourmaline", "variscite", "zircon", "corundum", "cubic zirconia", "moissanite", "amber", "ammolite", "bone", "coral", "ivory", "nacre", "jet", "pearl", "andalusite", "axinite", "benitoite", "bixbite", "cassiterite", "clinohumite", "iolite", "onyx", "kornerupine", "zeolite",];
 
var randValue = Math.floor(Math.random() * colors.length);
document.forms["ninja"].elements["crayons"].value = (colors[randValue]);
}
</script>

<form id="ninja">
  <p align="center">
    <textarea name="crayons" cols="50" rows="5" id="crayons"></textarea>
      </p><p align="center">
    <input type="button" value="Magic" onclick="displaymessage()">
  </p>
</form>
</body>
</html>



 

This code is being displayed with a WordPress plugin known as CodeColorer. I’m still fiddling with how it works. I’m hoping I can find a way to highlight multiple types of code in the same document without introducing a second table. I also want to figure out how to maintain the vertical scrolling while removing horizontal scrolling. I’ve recently discovered that I have a habit of inefficiently wandering websites in search of solutions to problems. I learn a bit of stuff that’s usually unrelated to the topic, but it’s not time efficient. Since coding has so much depth to it, I don’t always know when what I “want to do” is far out of reach of what I “can do.” Consequently, I’m trying to learn to leave problems alone and try to learn something else and/or approach the problem in another way.

This code combines HTML and Javascript. I know at a certain point, people are allowed to claim ownership of their source code. I doubt that applies here as it’s a relatively basic code. Plus I’d let others use it anyway. I hope to elaborate on this later by providing a more detailed analysis of each code section and what it is doing. I know a lot of tutorials/guides use generalized names for things. I’ve used labels like “crayons” and “magic.” I find unusual names much easier to deal with than things like “FormId1,” so expect to see more of that. Hope you find this somewhat helpful!

This entry was posted in Javascript. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>