www.webdeveloper.com
Results 1 to 3 of 3

Thread: Circle area calculator

  1. #1
    Join Date
    Dec 2002
    Posts
    216

    Circle area calculator

    Hi,

    I am trying to do a little script that calculates the area of a circle. It prompts before to ask for the radius then calculates. Well, it is supposed to do that. I tried but it doesn't give anything on the page.

    Can you please have a look to tell me what is wrong?


    <html>

    <HEAD>

    <SCRIPT LANGUAGE="JavaScript">

    function doArea(num) {
    var radius = prompt("Please enter the radius of the circle: ", "");
    return (Math.PI * Math.pow(radius, 2));
    }

    </script>
    </HEAD>

    <BODY>

    <script language="javascript">

    var radius = prompt("Please enter the radius of the circle: ", "");
    return (Math.PI * Math.pow(radius, 2));

    document.write("The area of the circle is " + " ")

    </form>
    </body>
    </html>

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Example</title>
    </head>
    <body>
    <script type="text/javascript">
    <!--
    document.write('<p>The area of the circle is ', Math.PI * Math.pow( prompt('Please enter the radius of the circle: ', ''), 2), '.</p>');
    // -->
    </script>
    </body>
    </html>
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Jun 2012
    Posts
    1

    Thumbs up circle area

    <html>

    <HEAD>

    <SCRIPT LANGUAGE="JavaScript">

    function doArea() {
    var radius =document.theform.rad.value;
    var result= (3.14 *radius*radius);
    alert("theareais"+result);

    }

    </script>
    </HEAD>


    <body>
    <form name="theform">
    <H2>enter the radius of the circle</h2>
    AREA:<input type="text" name="rad" ><br>
    <h3>find the area of circle below and give a clap now</h3>
    <input type="button" name="findarea" value="circle area" onclick="doArea()">
    </form>
    </body>

    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles