forked from AttilaVaczy/exam-2015-fall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.js
38 lines (30 loc) · 1.08 KB
/
3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
// Create a Circle constructor that creates a circle object:
// it should take the circle's radius as a parameter
// it should have a "getCircumference" method that returns it's circumference
// it should have a "getArea" method that returns it's area
// it should have a "toString" method that returns it's stats as a string like:
// 'Radius: 4, Circumference: 25.132741228718345, Area: 50.26548245743669'
function Circle(radius) {
this.radius = radius;
}
Circle.prototype.getCircumference = function() {
return 2 * this.radius * Math.PI;
}
Circle.prototype.getArea = function() {
return this.radius * this.radius * Math.PI;
}
Circle.prototype.toString = function() {
return `Radius: ${this.radius}, ` +
`Circumference: ${this.getCircumference()}, ` +
`Area: ${this.getArea()}`;
}
var circle = new Circle(4);
console.log(circle.radius);
console.log(circle.getCircumference());
console.log(circle.getArea());
console.log(circle.toString());
// 4
// 25.132741228718345
// 50.26548245743669
// Radius: 4, Circumference: 25.132741228718345, Area: 50.26548245743669