2. 수학 - 1~3.

2020. 7. 2. 14:32Retrospection/Sprint

1.

삼각형의 밑변과 높이가 주어졌을때, "computeAreaOfATriangle" 함수는 삼각형의 넓이를 반환합니다.

function computeAreaOfATriangle(base, height) {
  // your code here
}
function computeAreaOfATriangle(base, height) {
    return base * height * 1/2;
  // your code here
}

내가 한 방법은 위의 방법 

function computeAreaOfATriangle(base, height) {
  return (base * height) / 2;
}

이 코드처럼 괄호로 묶어서 2로 나누어도 된다.

 

2. 숫자와 지수가 주어졌을때, "computePower" 함수는 숫자의 지수만큼 제곱된 값을 반환해야 합니다.

function computePower(num, exponent) {
  // your code here
}
function computePower(num, exponent) {
    return Math.pow(num , exponent);
}

검색 키워드는 Javascript return power

Math.pow( a , b) 일때 a의 b 제곱을 리턴해준다. 

3.

원의 반지름이 주어졌을때, "computePerimeterOfACircle" 함수는 원의 둘레를 반환하세요

function computePerimeterOfACircle(radius) {
  // your code here
}
function computePerimeterOfACircle(radius) {
    return Math.PI * radius * 2;
}

처음엔 3.14를 곱했다가 답이 안나오길래 검색해봤다.

키워드는 javascript return radius .

Math.PI 는 파이의 값을 가진다. 

 

'Retrospection > Sprint' 카테고리의 다른 글

배열기초 /타입 1 , 배열기초 1-3  (0) 2020.07.04
2. 타입 1 ~3  (0) 2020.07.02
1. 문자열 7 , 8  (0) 2020.06.28
1. 문자열 4 ~ 6  (0) 2020.06.28
1. 문자열 1~3  (0) 2020.06.28