문제
초기화할 때 3개의 인수를 사용하는 JavaScript 클래스인 Projectile을 작성해야 합니다. −
Projectile 클래스에 대해 다음 메서드를 작성해야 합니다.
- 인수 t를 받아서 발사체가 이동한 수평 거리를 계산하는 수평 방법. [더블을 받고 더블을 반환]
예시
이 클래스의 코드는 -
class Projectile{
constructor(h, u, ang){
this.h = h;
this.u = u;
this.ang = ang;
};
};
Projectile.prototype.horiz = function(t){
const dist = 2 * Math.cos(this.ang) * t;
return dist;
};
const p = new Projectile(5, 2, 45);
const horizontal = p.horiz(.2);
console.log(horizontal); 출력
그리고 출력은 -
0.2101287955270919