Home > Article > Web Front-end > How to find the area of a circle using js
Method to calculate the circle area: 1. Create an input tag and receive the radius value; 2. Use "document.getElementById('id').value" to get the radius value in the input input box; 3. , use the area formula "area=3.14*(radius*radius)" to find the area of the circle.
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, Dell G3 computer.
The specific condition is to enter a radius, then find the area, round to 2 decimal places,
<!DOCTYPE html> <html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> </head> <body> 输入圆的半径:<input type="text" id="inp"> <input type="button" value="确定" onclick="test()"> </body> </html> <script> function test(){ var inp = parseFloat(document.getElementById('inp').value); var s = 3.14 * (inp * inp); alert('面积为:' + s) } </script>
[Recommended learning: javascript video tutorial]
The above is the detailed content of How to find the area of a circle using js. For more information, please follow other related articles on the PHP Chinese website!