如何在JavaScript中计算圆的面积和周长?
要计算圆的面积和周长,您可以尝试运行以下代码-
示例
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script>
function Calculate(r) {
this.r = r;
this.perimeter = function () {
return 2*Math.PI*this.r;
};
this.area = function () {
return Math.PI * this.r * this.r;
};
}
var calc = new Calculate(5);
document.write("Area of Circle = ", calc.area().toFixed(2));
document.write("<br>Perimeter of Circle = ", calc.perimeter().toFixed(2));
</script>
</body>
</html>热门推荐
10 祝福语生日男朋友简短
11 阳历新年祝福语大全 简短
12 60岁长辈祝福语简短
13 生日油画棒祝福语简短
14 新房开工文案祝福语简短
15 送水杯祝福语女生简短
16 给导师送花祝福语简短
17 庆祝国家的祝福语简短
18 老同学十一祝福语简短