Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions polygonSize.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>polygon</title>
</head>

<body>
<h2>다각형의 넓이 구하기</h2>
<script src = 'polygonSize.js'></script>
</body>

</html>
67 changes: 67 additions & 0 deletions polygonSize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
function sizeCircle(radius) {
if (toString.call(radius) != '[object Number]') {
return console.log('숫자만 계산 가능합니다.');
}
const circleArea = radius * radius * Math.PI
console.log('반지름이 ' + radius + '인 원의넓이는' + circleArea + '입니다.');
}
//test circle
console.log('원')
sizeCircle(4)
sizeCircle('문자')
sizeCircle();

function sizeSquare(lowerSide, height) {
if (lowerSide === undefined || height === undefined) {
return console.log('인자가 부족합니다.')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인자의 갯수를 확인하는 것이면,
arguments 갯수를 확인할 수도 있겠네요.

} else if (toString.call(lowerSide) != '[object Number]' || toString.call(height) != '[object Number]') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if(여기)
여기에 해당하는 부분을 별도 함수로 한번 만들어볼래요?
여기에 해당하는 코드와 로직이 길면 이를 하위함수로 많이 분리하기도해요.

return console.log('숫자만 계산 가능합니다.')
}
const squareArea = lowerSide * height
console.log('밑변과 높이가 ' + lowerSide + ', ' + height + '인 사각형의 넓이는' + squareArea + '입니다.')
}

//test square
console.log('사각형')
sizeSquare(4, 3)
sizeSquare(3)
sizeSquare()
sizeSquare('문자', '문자');
sizeSquare('문자');

function sizeTrapezoid(topSide, lowerSide, height) {
if (topSide === undefined || lowerSide === undefined || height === undefined) {
return console.log('인자가 부족합니다.')
} else if (toString.call(topSide) != '[object Number]' || toString.call(lowerSide) != '[object Number]' || toString.call(height) != '[object Number]') {
return console.log('숫자만 계산할 수 있습니다.')
}
const trapezoidArea = (topSide + lowerSide) * height / 2
console.log('윗변과 아랫변과 높이가 ' + topSide + ', ' + lowerSide + ', ' + height + '인 사다리꼴의 넓이는' + trapezoidArea + '입니다.')
}

//test trapezoid
console.log('사다리꼴')
sizeTrapezoid(2, 3, 4)
sizeTrapezoid(2, 3)
sizeTrapezoid('문자', 2, 3)
sizeTrapezoid('문자', '문자', '문자')
sizeTrapezoid()

function sizeSylinder(radius, height) {
if (radius === undefined || height === undefined) {
return console.log('인자가 부족합니다.')
} else if (toString.call(radius) != '[object Number]' || toString.call(height) != '[object Number]') {
return console.log('숫자만 계산할 수 있습니다.')
}
const sylinderArea = (Math.PI * radius * radius) + ((2 * radius * Math.PI) * height)
console.log('반지름과 높이가' + radius + ', ' + height + '인 원기둥의 겉넓이는 ' + sylinderArea + '입니다.')
}

//test sizeSylinder
console.log('원기둥')
sizeSylinder(2, 3)
sizeSylinder(2)
sizeSylinder('문자')
sizeSylinder('문자', 3)
sizeSylinder()