Monday, June 18, 2012

random function generator with array code

press the refress button to see random gems alert

gems.length has been commented out replace with number 3


<! DOCTYPE HTML>
 <html>
  <head>
   <title>looparray</title>
   <script type="text/javascript">
    var gems=new Array("diamond","ruby","saphire","emerald");
    gemItem = Math.round(Math.random()*3);//gems.length
    alert(gems[gemItem]);
   
   </script>
  </head>
   <body>
   </body>
 </html>

No comments:

Post a Comment