javascript - Function not running, no error on firefox -


so, i'm working on random sentence generator. i'm trying work, function not seem running (this saved html file , i'm running in firefox). here's code far:

<html>    <body>    <h1>hello.</h1>    <br>    <p>this website made me. no, not own domain. however, can run file computer. looking @ website. please enjoy!</p>    hey! @ button made! i'm working on more stuff @ this.    <button onclick="generatesentence()">click me random sentence!</button>    <p id="output"></p>    <script>      function generatesentence() {        alert("test")        var subjectran = math.floor(math.random() * subject.length)        var verbran = math.floor(math.random() * verb.length)        var adjectiveran = math.floor(math.random() * adjective.length)        var objectran = math.floor(math.random() * object.length)        var adverbran = math.floor(math.random() * adverb.length)        var subject = ["perry", "obama", "liam", "eric", "gregory", "daniel", "mikey", "pog", "benji", "raj", "jarec", "theo", "zach", "nicholas", "samir", "ivan", "colonel sanders", "sk"]        var verb = ["eats", "hates", "loves", "dyes", "kills", "dreams about", "runs with", "deep-fries", "fries", "burns", "ignites", "texts", "harvests", "stores", "runs over", "buys", "sells", "explodes", "studies", "destroys", "breaks", "reks", "bodies", "mauls", "melts", "pops", "slices", "butchers", "has nightmares about", "has flashbacks about", "jars", "thinks about", "makes art with", "builds house with", "writes with"]        var adjective = ["dank", "red", "orange", "yellow", "green", "blue", "indigo", "violet", "purple", "white", "black", "brown", "red-orange", "yellow-green", "dumb", "stupid", "smart", "", "rainbow", "titanium", "adamantium", "paper", "black , white", "sad", "happy", "angry", "flat", "winded", "donated", "edible", "fat", "slow", "fast", "energetic", "lazy", "hot", "cold", "dead"]        var object = ["toys", "cars", "ferraris", "mustangs", "maseraties", "buses", "people", "heads", "blocks", "houses", "cheeses", "teletubbies", "gengis kahns", "mustaches", "cows", "pigs", "chickens", "houses", "nicholas cages", "george washingtons", "kim jong uns", "calculators", "tables", "schools", "classes", "suits", "pencils", "fried chicken", "sheep", "moose", "sinks", "beans", "tomatoes", "peas", "pumpkins", "tater tots", "hotdogs", "lemons"]        var adverb = ["", "quickly", "often", "slowly", "carefully", "correctly", "eagerly", "easily", "fast", "loudly", "quietly", "patiently", "outside", "somewhere", "downstairs", "abroad", "underground", "upstairs", "anywhere", "accidentally", "intentionally", "seldom", "sometimes", "usually", "rarely", "here"]        ver sentence = (subject[subjectran] + " " + verb[verbran] + " " + adjective[adjectiveran] + " " + object[objectran] + " " + adverb[adverbran])        document.getelementbyid("output").innerhtml = sentence      }    </script>  </body>    </html>

the snippet says error "missing ; before statement", not errors when running in firefox. remember, i'm kind of amateur. did make mistake, or supposed work? in advance.

edit: after looking @ 3 comments, saw mistakes hadn't noticed looked over. also, unaware arrays weren't working reason. helping!

here's html corrections:

<html> <body> <h1>hello.</h1><br> <p>this website made me. no, not own domain. however, can run file computer. looking @ website. please enjoy!</p> hey! @ button made! i'm working on more stuff @ this.<button onclick="generatesentence();">click me random sentence!</button> <p id="output"></p> <script> function generatesentence(){     alert("test");     var subject = ["perry","obama","liam","eric","gregory","daniel","mikey","pog","benji","raj","jarec","theo","zach","nicholas","samir","ivan","colonel sanders","sk"];     var verb = ["eats","hates","loves","dyes","kills","dreams about","runs with","deep-fries","fries","burns","ignites","texts","harvests","stores","runs over","buys","sells","explodes","studies","destroys","breaks","reks","bodies","mauls","melts","pops","slices","butchers","has nightmares about","has flashbacks about","jars","thinks about","makes art with","builds house with","writes with"];     var adjective = ["dank","red","orange","yellow","green","blue","indigo","violet","purple","white","black","brown","red-orange","yellow-green","dumb","stupid","smart","","rainbow","titanium","adamantium","paper","black , white","sad","happy","angry","flat","winded","donated","edible","fat","slow","fast","energetic","lazy","hot","cold","dead"];     var object = ["toys","cars","ferraris","mustangs","maseraties","buses","people","heads","blocks","houses","cheeses","teletubbies","gengis kahns","mustaches","cows","pigs","chickens","houses","nicholas cages","george washingtons","kim jong uns","calculators","tables","schools","classes","suits","pencils","fried chicken","sheep","moose","sinks","beans","tomatoes","peas","pumpkins","tater tots","hotdogs","lemons"];     var adverb = ["","quickly","often","slowly","carefully","correctly","eagerly","easily","fast","loudly","quietly","patiently","outside","somewhere","downstairs","abroad","underground","upstairs","anywhere","accidentally","intentionally","seldom","sometimes","usually","rarely","here"];      var subjectran = math.floor(math.random()*subject.length);     var verbran = math.floor(math.random()*verb.length);     var adjectiveran = math.floor(math.random()*adjective.length);     var objectran = math.floor(math.random()*object.length);     var adverbran = math.floor(math.random()*adverb.length);     var sentence = (subject[subjectran] + " " + verb[verbran] + " " + adjective[adjectiveran] + " " + object[objectran] + " " + adverb[adverbran]);     document.getelementbyid("output").innerhtml = sentence; } </script> </body> </html> 
  • amended ver var.
  • added semicolons.
  • renamed math math.
  • put arrays before other code require them.

you should consider moving arrays outside of function don't keep initializing them.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo