-
Notifications
You must be signed in to change notification settings - Fork 0
/
circle.js
41 lines (39 loc) · 1020 Bytes
/
circle.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
39
40
class Circle{
constructor(radius,color){
this._radius = radius.toFixed(1);
this._color = color;
}
get radius(){
return this._radius;
}
set radius(newRadius){
if(newRadius < 0){
console.log("Error:value have to be positive");
}else{
this._radius = newRadius;
}
}
get color(){
return this._color;
}
set color(newColor){
if(newColor !== this._color){
this._color = newColor;
}else{
console.log(`Error:${this._color} already exist please enter another color`);
}
}
getArea(){
console.log(`
The Area of the given radius is ${(Math.PI * this._radius * this._radius).toFixed(1)}
`);
}
getCircumference(){
console.log(`
The circumference of the given radius is ${(2 * Math.PI * this._radius).toFixed(1)}
`);
}
}
const circle = new Circle(2,"blue");
circle.getArea();
circle.getCircumference();