i'm working on random art prompt generator, i'd improve code adding section saves previous results , displays them beneath "search" section aren't lost right away. maybe cache of 10 or so? have no idea how begin.
function getvalue() { var myarray1 = new array("vibrating", "eye-popping", "busy", "bold", "garish", "stunning", "nauseating", "powerful", "simple", "boring", "graphic", "clashing", "harmonious", "multicolored"); var myarray2 = new array("political", "dreamy", "epic", "biblical", "romantic", "natural", "violent", "serene", "literary", "assymetrical", "symetrical"); var myarray3 = new array("dull", "dark", "bright", "vivid", "vibrant", "primary-colored", "muddy", "rough", "shiny", "grainy", "glossy"); var myarray4 = new array("monochromatic", "black-and-white", "fluorescent", "brown", "earthtone", "pink", "two-tone", "green"); var myarray5 = new array("cubist", "classical", "folksy", "minimalist", "realist", "expressionist", "modernist", "conceptual"); var myarray6 = new array("painting", "drawing", "sculpture", "diorama", "cut-out", "collage","video","photograph","flipbook","woodblock print", "drypoint", "etching"); var random1 = myarray1[math.floor(math.random() * myarray1.length)]; var random2 = myarray2[math.floor(math.random() * myarray2.length)]; var random3 = myarray3[math.floor(math.random() * myarray3.length)]; var random4 = myarray4[math.floor(math.random() * myarray4.length)]; var random5 = myarray5[math.floor(math.random() * myarray5.length)]; var random6 = myarray6[math.floor(math.random() * myarray6.length)]; var output = random1 + ' ' + random2 + ' ' + random3 + ' ' + random4 + ' ' + random5 + ' ' + random6; document.getelementbyid("message").innerhtml = output; }
<input type="button" id="btnsearch" value="search" onclick="getvalue();" /> <p id="message">
you use global variable last string , prepend list. if more 10 item, latest item becomes deleted.
function getvalue() { var words = [["vibrating", "eye-popping", "busy", "bold", "garish", "stunning", "nauseating", "powerful", "simple", "boring", "graphic", "clashing", "harmonious", "multicolored"], ["political", "dreamy", "epic", "biblical", "romantic", "natural", "violent", "serene", "literary", "assymetrical", "symetrical"], ["dull", "dark", "bright", "vivid", "vibrant", "primary-colored", "muddy", "rough", "shiny", "grainy", "glossy"], ["monochromatic", "black-and-white", "fluorescent", "brown", "earthtone", "pink", "two-tone", "green"], ["cubist", "classical", "folksy", "minimalist", "realist", "expressionist", "modernist", "conceptual"], ["painting", "drawing", "sculpture", "diorama", "cut-out", "collage", "video", "photograph", "flipbook", "woodblock print", "drypoint", "etching"]], output = words.map(function (a) { return a[math.floor(math.random() * a.length)]; }).join(' '), list = document.getelementbyid("last"), li; if (last){ list.childnodes.length > 9 && list.removechild(list.childnodes[9]); li = document.createelement('li'); li.innerhtml = last; if (list.childnodes.length) { list.insertbefore(li, list.childnodes[0]); } else { list.appendchild(li); } } document.getelementbyid("message").innerhtml = output; last = output; } var last = '';
<input type="button" id="btnsearch" value="search" onclick="getvalue();" /> <p id="message"></p> <ul id="last"></ul>
Comments
Post a Comment