Results 1 to 2 of 2

Thread: JavaScript Random #s

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210
    How do i generate a random numnber (a 1 or a 0) in javascript and then play a sound if the number is a 1?
    < o >

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    One staep at a time please!

    Here's the code for a random 0 or 1...

    Code:
    <html>
    <SCRIPT LANGUAGE="JavaScript">
    
    function z() {
    	
    var x = Math.floor(Math.random() * 2)
    	
    document.frm1.Text1.value= x
    
     if(x==1)
     {
    
     alert("Code to play sound required here!")
     }
    
    }			
    
    </script>
    </html>
    <body>
    <FORM NAME="frm1">
    <INPUT NAME="Text1" VALUE="" SIZE="3"><BR>
    <INPUT TYPE="BUTTON" onClick="z();" value="Click"><BR>
    </FORM>
    </body>
    </html>
    Mark
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width