+ 2

How to generate random word

how to generate a random word?

24th Nov 2016, 12:21 AM
Rodrigo Tallar
Rodrigo Tallar - avatar
1 Answer
+ 1
var words = ["Apple", "Banana", "Orange", "Water", "Javascript", "ECMA", "Rodrigo"]; document.write(words[Math.floor(Math.random() * words.length)]); Just a random word. For interactive :) => <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <span id="span"></span> <script> var words = ["Apple", "Banana", "Orange", "Water", "Javascript", "ECMA", "Rodrigo","More","Words"]; function myFunc (arr) { var span = document.getElementById('span'); span.innerHTML = arr[Math.floor(Math.random() * arr.length)]; } var interval = setInterval(function () {myFunc(words)},1000 ); </script> </body> </html> I hope that helped
27th Nov 2016, 2:57 PM
alexyork
alexyork - avatar