-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagicKitchenWorkshop.js
More file actions
96 lines (84 loc) · 2.54 KB
/
magicKitchenWorkshop.js
File metadata and controls
96 lines (84 loc) · 2.54 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// FACTORY FUNCTION
// This is the Diagon Alley contractor workshop itself
// It always builds the same base kitchen first
// I added a beef detector because I'm allergic to beef. It's a personal touch
function buildBaseKitchen() {
return {
concealedFromMuggles: true,
cauldron: true,
beefIngredientDetector: true,
countertops: true,
pantry: true,
oven: true,
qualityControlElf: "Assigned",
features: [],
};
}
// Patrons will need to choose from one of the existing classes, or types of kitchen builds
// CLASS 1: Defense Against the Dark Farts
// This is a certified kitchen TYPE
// It does not build kitchens
// It upgrades a kitchen according to strict rules
class DefenseAgainstTheDarkFartsKitchen {
applyTo(kitchen) {
kitchen.flatulenceReductionLevel = "High";
kitchen.features.push("Anti dark farts enchantments");
return kitchen;
}
}
// CLASS 2: Werewolf Kitchen
// Another certified kitchen TYPE
// Also upgrades an existing kitchen
class WerewolfKitchen {
applyTo(kitchen) {
kitchen.dogBed = true;
kitchen.boneRack = [
"chicken",
"cow",
"goat",
"whale",
"mermaid",
"mystery creature",
];
kitchen.moonPhaseClock = true;
kitchen.features.push("Werewolf accommodations");
return kitchen;
}
}
// WORKSHOP ORDER PROCESS
// This is where the wizard makes the required choice
function magicKitchenWorkshop(kitchenType) {
const kitchen = buildBaseKitchen();
if (kitchenType === "defense") {
const upgrade = new DefenseAgainstTheDarkFartsKitchen();
return upgrade.applyTo(kitchen);
}
if (kitchenType === "werewolf") {
const upgrade = new WerewolfKitchen();
return upgrade.applyTo(kitchen);
}
throw new Error("Wizard must choose a certified kitchen type");
}
// EXAMPLES
const mollyKitchen = magicKitchenWorkshop("defense");
const remusKitchen = magicKitchenWorkshop("werewolf");
//magicKitchenInstallation
// INSTALLER CLASS
// This class does not design or upgrade kitchens
// It manages a specific installation
class KitchenInstaller {
constructor(kitchen, wizardName) {
// Here is where Codecademy’s explanation of `this` applies
// `this` refers to the installer instance
// The installer now owns the installed kitchen
this.kitchen = kitchen;
this.installedFor = wizardName;
this.installed = false;
}
install() {
this.installed = true;
return `Kitchen successfully installed for ${this.installedFor}`;
}
}
//How to call the class above
const installer = new KitchenInstaller(werewolfKitchen, "Remus");