#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    19
    Rep Power
    0

    Find square root by prompt in javascript


    I am new to this Javascript
    I want to design a webpapge using javascript which would find the square root of number using prompt dialog box from user.
    I had written code as below but cannot get number through prompt.
    How to get number through prompt function in java script
    <script>
    function myFunction()
    {
    var x;

    var x=prompt("Enter number for square root","enter number");

    if (x!=null)
    {
    x="Square root of " + x;
    document.getElementById("demo").innerHTML=Math.sqrt(x);
    }
    }
    </script>

    Thanks a lot in advance
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Location
    Saint-Petersburg, Russia
    Posts
    240
    Rep Power
    29
    x="Square root of " + x;
    document.getElementById("demo").innerHTML=Math.sqrt(x);
    Didn't you see you have written text into X before getting sqrt of it? obviously this will fail...

IMN logo majestic logo threadwatch logo seochat tools logo