How To Get The Value Of PI Using JavaScript Example?


Share:
Published By: Admin, Published On: Nov 02, 2021, Category: Javascript


Hello Friends,

Now let's see example of how to get value of PI example. We will use how to get value of PI in javascript. Here you will learn how to get value of PI. Let's get started with how to get value of PI in javascript.

Here i will give you many example how to get value of PI javascript.

Example : 1
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>How To Get The Value Of PI Using JavaScript Example? - MyWebtuts.com</title>
    </head>
    <body>
        <p>Welcome to the MyWebtuts.com</p>
        <p>Click the following button to get the value of PI. </p>
        <p id = "d1"></p>
        <button onclick = "get()">Click me</button>
       
        <script type="text/javascript">
            function get() 
            { 
                document.getElementById("d1").innerHTML = "The value of PI is: " + Math.PI;
            }
        </script>
    </body>
</html>
Output :
Welcome to the MyWebtuts.com
Click the following button to get the value of PI.
The value of PI is: 3.141592653589793
Example : 2
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>How To Get The Value Of PI Using JavaScript Example? - MyWebtuts.com</title>
    </head>
    <body>
        <p>Welcome to the MyWebtuts.com</p>
        <p id = "d1"></p>
        
        <script type="text/javascript">
            var r = area(8);
            document.getElementById('d1').innerHTML = 'The area of circle with radius 8 is: ' + r ;
            function area(radius) 
            { 
                return Math.PI * radius * radius;
            }
        </script>
    </body>
</html>
Output :
Welcome to the MyWebtuts.com
The area of circle with radius 8 is: 201.06192982974676

It will help you...

Share: