원의 면적과 둘레를 계산하려면 다음 코드를 실행해 보십시오. -
예
<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>