Sunday, August 8, 2021

Area of the Circle Using JavaScript

 A simple program to ask the user to give radius value and then the program will convert the given radius into area of the circle using JavaScript programming language,

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website, kindly contact me also at my email address also. Thank you.

My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.





Program Listing

index.htm

<html>
   <title>Area of the Circle in JavaScript</title>
 <style type="text/css">

 body {

  font-familyarial;
  font-weightbold;
  font-size:15px;
   }
 
 form
{
  displayinline-block;
  background-colorlightblue;
  padding6px;
}

label{
  displayblock;
  directionrtl
}

input{
  directionltr
}

label::after{
  contentattr(data-text);
}
 </style>

<script language="JavaScript">

function Solve(){

if (document.circle.radius.value === "" || document.circle.radius.value === "0" ) {
  alert("Cannot be empty. Try Again");
  document.circle.radius.focus();
else {

a = parseInt(document.circle.radius.value);

result = "The area of the circle is " + (a * a * Math.PI).toFixed(2);
document.getElementById("tag").innerHTML = result;
  }
}

function Clear() {
document.circle.radius.value ="";
document.getElementById("tag").innerHTML = "";
document.circle.radius.focus();
 }

</script>
<body>
<br>
<h3>Area of the Circle in JavaScript</h3>
<form name="circle">
<label data-text="Enter the radius of circle">&nbsp;&nbsp;
<input type="number" name="radius" autofocus required>
</label>
<br/>
<span id="tag"></span>
 <br><br>
<input type="button" value="Convert" title="Click here to solve." onclick="Solve()" />
<input type="button" value="Clear"  
title="Click here to clear the text box."
onclick="Clear()"/>
</form>
</body>
</html>


No comments:

Post a Comment