Create paragraph from random array of words - Javascript Array Operation

Javascript examples for Array Operation:Array Index

Description

Create paragraph from random array of words

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//w  w  w. ja v  a2 s .c o m
var words = ['apple', 'beer', 'cake', 'potato', 'orange','test','joe'],
    div = document.getElementById('foo');
for(i = 0; i < 50; i++) {
    div.innerHTML += ' ' + words[Math.floor(Math.random() * words.length)];
}
    });

      </script> 
   </head> 
   <body> 
      <div id="foo"></div>  
   </body>
</html>

Related Tutorials