4
06/11/2024 9:13 오전
주제 스타터
I must write a JavaScript function that calculates circle area by given radius. Print the area as it is calculated and then print it rounded to two decimal places.
- The input comes as a single number argument - the radius of the circle.
- The output should be printed to the console on a new line for each result.
Example:
입력: 5
출력:
78.53981633974483
78.54
2개 답글
3
06/11/2024 9:14 오전
My code is:
function circleArea(radius) { let area = Math.PI * (radius * radius); console.log(area); console.log(Math.round(area*100)/100); } circleArea(5);
1
06/11/2024 9:15 오전
Two solutions from me:
function circleA(r) { console.log(Math.PI * r * r); console.log(Math.round(Math.PI * r * r * 100) / 100); } circleA(5);
function cA(rad) { let area = Math.PI * rad * rad; console.log(area); let areaRounded = Math.round(area * 100) / 100; console.log(areaRounded); } cA(5);