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 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2006
    Location
    Toronto
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Javascript square root

    Sorry, I'm still a novice at Javascript. I cannot manage to do a square root operation. I am using the coding:
    var a = Math.sqrt(b);
    Anyhelp would be appreciated. Thanks.
    var currentTime = new Date()
    var chance = currentTime.getTime()
    var chance2 = chance % 3
    alert(chance2)

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Looks fine to me as long as b is an integer. Try just typing

    alert(Math.sqrt(9));

    and see if it returns 3 to cut out the guesswork

    david_kw

  • #3
    New Coder
    Join Date
    Sep 2006
    Location
    Toronto
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    For some reason, putting it into an alert worked, and it also worked with a variable. Thanks a lot, David
    var currentTime = new Date()
    var chance = currentTime.getTime()
    var chance2 = chance % 3
    alert(chance2)

  • #4
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Square root

    b definitely does not have to be an integer, it can be any real number (ie loads of decimal places will work).

    Dave


  •  

    Posting Permissions

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