Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2003
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    random whole number

    ok, i'm very new at javascripting and just ran into a problem. I want to have a random whole number but with this code I get a decimal. Would any of you know how to fix this?



    <form>
    <input type="button" value="random number" onClick="alert(Math.random()*11)">
    </form>

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <form>
    <input type="button" value="random number" onclick="alert(Math.round(Math.random()*11))">
    </form>

  • #3
    New Coder
    Join Date
    Dec 2003
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much Skyzyx, that is exactly what I wanted.


  •  

    Posting Permissions

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