-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (59 loc) · 1.19 KB
/
index.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
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
/*
- Create ColorConsole class with log() method
- Create subclasses, RedConsole, BlueConsole, GreenConsole
- Create factory function to return correct class based on argument
- Write CLI script for use
*/
/*
PARENT CLASS
*/
class ColorConsole {
constructor(string, terminal){
this.string = "I am " + string
this.terminal = terminal
}
log(){
console.log(`${this.terminal}%s\x1b[0m`, this.string)
}
}
/*
CHILD CLASSES
*/
// RED
class RedConsole extends ColorConsole {
constructor(){
super('red','\x1b[31m')
}
}
// GREEN
class GreenConsole extends ColorConsole {
constructor(){
super('green','\x1b[32m')
}
}
// BLUE
class BlueConsole extends ColorConsole {
constructor(){
super('blue','\x1b[34m')
}
}
/*
FACTORY METHOD
*/
function colorFactory(string){
switch(string){
case 'red':
return new RedConsole()
case 'blue':
return new BlueConsole()
case 'green':
return new GreenConsole()
default:
console.log(`Did not understand choice. Please select red, blue, or green`)
}
}
/*
CLI RUN
*/
let color = colorFactory(process.argv[2])
color.log()