javascript - word won't print on button press [JS, HTML] -
i'm confused why on button press not outputting word. if me solve this, appreciated. i've tried searching in other places don't know if unique problem have (not likely) or if i'm not @ searching stuff on google.
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title> seth's pictionary word generator </title> <link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-bvyiisifek1dgmjrakycuhahrg32omucww7on3rydg4va+pmstsz/k68vbdejh4u" crossorigin="anonymous"> <script> function numgen() { num = return math.floor((math.random() * 43) + 1) window.num = nnum; } var ewords = ["cat", "sun", "cup", "ghost", "flower", "pie", "cow", "banana", "snowflake", "bug", "book", "jar", "snake", "light", "tree", "lips", "apple", "slide", "socks", "smile", "swing", "coat", "shoe", "water", "heart", "hat", "ocean", "kite", "dog", "mouth", "milk", "duck", "eyes", "skateboard", "bird", "boy", "apple", "person", "girl", "mouse", "ball", "house", "star", "nose", "bed", "whale", "jacket", "shirt", "hippo", "beach", "egg", "face", "cookie", "cheese", "ice cream code", "drum", "circle", "spoon", "worm", "spider web"]; function write() { var word = ewords[nnum] document.getelementbyid("wordplace").innerhtml = word; } </script> </head> <body> <h1 align="center" class="head">seth's pictionary generator</h1> <p align="center" class=b> home of <strong> best </strong> pictionary generator on web.</p> <div id="wordplace"> </div> <p align="center"> <button class="btn btn-primary" onclick="numgen() write()"> generate word! </button> </p> <footer class=footer> <div align="center" class=foot-div> created gp_swade -- github.com/swodobaggins/pictionary-generator </div> </footer> </body> </html>
my modified, working code: (for reason jsfiddle , similar sites not work, on localhost works perfectly)
update: working on jsfiddle (just change js "load type" "no wrap - in < head>" ): https://jsfiddle.net/gy2ofu26/
... ... <script> var nnum; function numgen() { num = math.floor((math.random() * 43) + 1); nnum = num; } var ewords = ["cat", "sun", "cup", "ghost", "flower", "pie", "cow", "banana", "snowflake", "bug", "book", "jar", "snake", "light", "tree", "lips", "apple", "slide", "socks", "smile", "swing", "coat", "shoe", "water", "heart", "hat", "ocean", "kite", "dog", "mouth", "milk", "duck", "eyes", "skateboard", "bird", "boy", "apple", "person", "girl", "mouse", "ball", "house", "star", "nose", "bed", "whale", "jacket", "shirt", "hippo", "beach", "egg", "face", "cookie", "cheese", "ice cream code", "drum", "circle", "spoon", "worm", "spider web"]; function write(){ var word = ewords[nnum]; document.getelementbyid("wordplace").innerhtml = word; } function callfunc(){ numgen(); write(); } </script> ... ... <button class="btn btn-primary" onclick="callfunc();">
Comments
Post a Comment