forked from wijaksanapanji/learn-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchinkeki.html
76 lines (68 loc) · 2.65 KB
/
chinkeki.html
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
```html
<!DOCTYPE html>
<html>
<body>
<script>
//3. Create class named `TrafficLight`.
class TrafficLight {
constructor(color, address) {
//4. Add `color` and `address` to it.
this._color = color;
this._address = address;
}
//6. Add a method named `getColor` to get `color`
get getColor() {
return this._color;
}
//7. Add a method name `canGo` that checks color and if it is `green` returns true, else false.
canGo(color) {
if (this._color === 'green') {
return true;
} else {
return false;
}
}
}
//8. Create class named `VIPTrafficLight` inherits from `TrafficLight`
class VIPTrafficLight extends TrafficLight {
constructor(color, address, specialEffects) {
super(color, address);
//9. Add field `SpecialEffects` to this class.
this._specialEffects = specialEffects;
}
//11. Add method getSpecialEffects() to return the effect.
get getSpecialEffects() {
return this._specialEffects;
}
//12. Add method setSpecialEffects() to set the effect.
//If it not `dotted`, `solid` or `dashed` do not set and log `No valid Effect`.
set setSpecialEffects(specialEffects) {
switch (specialEffects) {
case 'dotted':
this._specialEffects = specialEffects;
break;
case 'solid':
this._specialEffects = specialEffects;
break;
case 'dashed':
this._specialEffects = specialEffects;
break;
default:
console.log('No valid Effect');
break;
}
}
}
//5. Create an instance `myTL` and set`color` to `red` and `address` to `Avenue 1`
const myTL = new TrafficLight('red', 'Avenue 1');
//6. Add a method named `getColor` to get `color` and call with console.log to show into console.
console.log(myTL.getColor);
console.log(myTL.canGo());
//10. Create an instance named `myVIP` and set SpecialEffects to `dotted`.
const myVIP = new VIPTrafficLight('red', 'Avenue 1', 'dotted');
myVIP.setSpecialEffects = 'solid';
console.log(myVIP._specialEffects);
</script>
</body>
</html>
```