댓글 검색 목록

[javascript] 원의 면적과 둘레를 계산하는 JavaScript 프로그램 작성하시오.

페이지 정보

작성자 운영자 작성일 17-12-30 17:39 조회 1,545 댓글 0

코드 :

function circle(radius)
{
    this.radius = radius;
  // area method
    this.area = function () 
    {
        return Math.PI * this.radius * this.radius;
    };
  // perimeter method
    this.perimeter = function ()
    {
        return 2*Math.PI*this.radius;
    };
}
var c = new circle(3);
console.log('원의 면적 =', c.area().toFixed(2));
console.log('원의 둘레 =', c.perimeter().toFixed(2));


결과 :

원의 면적 =28.27

원의 둘레 =18.85



댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

코리아뉴스 2001 - , All right reserved.