HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<h1>Check the console tab to see the logs</h1>
@media (prefers-color-scheme: dark) {
body {
background-color: #1D1E22;
color: #fff;
}
}
//#region availableItems
const availableBreakfastItems = {
proteins: ["Chicken", "Sausage", "Egg"],
toppings: ["Lettuce", "Cheese", "Tomato", "Onion", "Pepper"],
breads: ["English Muffin", "Plain Bagel", "Sesame Bagel", "Tortilla", "Hotcakes"],
sauces: ["Salsa", "Syrup", "Mayo"]
};
const availableBreakfastSideItems = {
sides: ["Hash Browns", "Apple Slices"],
sizes: ["Regular", "Medium", "Large"],
};
const availableBreakfastDrinkItems = {
drinks: ["Coffee", "Tea", "Orange Juice", "Milk"],
sizes: ["Regular", "Medium", "Large"],
addIns: ["Sugar", "Cream", "Milk", "Whipped Cream"]
};
const availableLunchItems = {
patties: ["Burger", "Chicken", "Fishish"],
toppings: ["Lettuce", "Cheese", "Tomato", "Onion", "Pepper", "Pickle"],
buns: ["Regular", "Sesame Seed", "Three Layer Sesame Seed", "Steamed"],
sauces: ["Ketchup", "Mayo", "Mustard", "Relish", 'Big Mac Sauce']
};
const availableLunchSideItems = {
sides: ["Fries", "Onion Rings", "Chicken Salad"],
sizes: ["Regular", "Medium", "Large"],
sauces: ["Ketchup", "Mayo", "Ranch"]
};
const availableLunchDrinkItems = {
drinks: ["Coke", "Pepsi", "Sprite", "Orange Crush"],
sizes: ["Regular", "Medium", "Large"],
addIns: ["Ice"]
};
// #endregion availableItems
//#region Products
class BreakfastItem {
currentItemProteins = [];
currentItemToppings = [];
currentItemSauces = [];
}
class LunchItem {
currentItemPatties = [];
currentItemToppings = [];
currentItemSauces = [];
}
class SidesItem {
sides = {};
}
class DrinksItem {
drinks = {};
}
//#endregion Products
//#region Abstract Builder Interfaces
class BreakfastItemInterface {
constructor() {
if (new.target === BreakfastItemInterface) {
throw new TypeError("Cannot instantiate BreakfastInterface");
}
}
reset() {
throw new Error("Must implement method");
}
addName(name) {
throw new Error("Must implement method");
}
addBread(bread) {
throw new Error("Must implement method");
}
addProtein(protein) {
throw new Error("Must implement method");
}
addTopping(topping) {
throw new Error("Must implement method");
}
addSauce(sauce) {
throw new Error("Must implement method");
}
addButter() {
throw new Error("Must implement method");
}
addCreamCheese() {
throw new Error("Must implement method");
}
build() {
throw new Error("Must implement method");
}
}
class BreakfastSideItemInterface {
constructor() {
if (new.target === LunchSideItemInterface) {
throw new TypeError("Cannot instantiate BreakfastSides");
}
}
reset() {
throw new Error("Must implement method");
}
addSide(side, size) {
throw new Error("Must implement method");
}
build() {
throw new Error("Must implement method");
}
}
class BreakfastDrinkItemInterface {
constructor() {
if (new.target === BreakfastDrinkItemInterface) {
throw new TypeError("Cannot instantiate DrinkInterface");
}
}
reset() {
throw new Error("Must implement method");
}
addDrink(drink, size, addIn) {
throw new Error("Must implement method");
}
build() {
throw new Error("Must implement method");
}
}
class LunchItemInterface {
constructor() {
if (new.target === LunchItemInterface) {
throw new TypeError("Cannot instantiate BurgerInterface");
}
}
reset() {
throw new Error("Must implement method");
}
addName(burger) {
throw new Error("Must implement method");
}
addBun(bun) {
throw new Error("Must implement method");
}
addPatty(patty) {
throw new Error("Must implement method");
}
addTopping(topping) {
throw new Error("Must implement method");
}
addSauce(sauce) {
throw new Error("Must implement method");
}
addNapkin() {
throw new Error("Must implement method");
}
build() {
throw new Error("Must implement method");
}
}
class LunchSideItemInterface {
constructor() {
if (new.target === LunchSideItemInterface) {
throw new TypeError("Cannot instantiate BreakfastSides");
}
}
reset() {
throw new Error("Must implement method");
}
addSide(side, size) {
throw new Error("Must implement method");
}
addSauce(sauce) {
throw new Error("Must implement method");
}
build() {
throw new Error("Must implement method");
}
}
class LunchDrinkItemInterface {
constructor() {
if (new.target === LunchDrinkItemInterface) {
throw new TypeError("Cannot instantiate DrinkInterface");
}
}
reset() {
throw new Error("Must implement method");
}
addDrink(drink, size, addIn) {
throw new Error("Must implement method");
}
build() {
throw new Error("Must implement method");
}
}
// #endregion Abstract Builder Interfaces
//#region Concrete Builders
class BreakfastItemBuilder extends BreakfastItemInterface {
availableItems = structuredClone(availableBreakfastItems);
breakfastItem = new BreakfastItem();
reset() {
this.breakfastItem = new BreakfastItem();
}
addName(name) {
this.breakfastItem.name = name;
return this;
}
addBread(bread) {
if (this.availableItems.breads.includes(bread)) {
this.breakfastItem.bread = bread;
return this;
} else {
console.log("We're all out or that type of bread does not exist:", bread);
}
}
addProtein(protein) {
if (this.availableItems.proteins.includes(protein)) {
this.breakfastItem.currentItemProteins.push(protein);
return this;
} else {
console.log("We're all out or that type of protein does not exist", protein);
}
}
addTopping(topping) {
if (this.availableItems.toppings.includes(topping)) {
this.breakfastItem.currentItemToppings.push(topping);
return this;
} else {
console.log("We're all out or that type of topping does not exist", topping);
}
}
addSauce(sauce) {
if (this.availableItems.sauces.includes(sauce)) {
this.breakfastItem.currentItemSauces.push(sauce);
return this;
} else {
console.log("We're all out or that type of sauce does not exist", sauce);
}
}
addButter() {
this.breakfastItem.butter = true;
return this;
}
addCreamCheese() {
this.breakfastItem.creamCheese = true;
return this;
}
build() {
const builtBreakfastItem = this.breakfastItem;
this.reset();
return builtBreakfastItem;
}
}
class BreakfastSideBuilder extends BreakfastSideItemInterface {
availableSideItems = structuredClone(availableBreakfastSideItems);
sidesItem = new SidesItem();
reset() {
this.sidesItem = new SidesItem();
}
addSide({ side, size } = {}) {
const options = { side: false, size: 'Regular', ...arguments[0] };
if (options.size && !this.availableSideItems.sides.includes(options.side)) {
console.log("We're all out or this type of side does not exist", options.side);
return this;
}
if (!this.sidesItem.sides[options.side]) {
this.sidesItem.sides[options.side] = {};
}
if (this.sidesItem.sides[options.side][options.size]) {
this.sidesItem.sides[options.side][options.size] += 1;
} else {
this.sidesItem.sides[options.side][options.size] = 1;
}
return this;
}
build() {
return this.sidesItem;
}
}
class BreakfastDrinkBuilder extends BreakfastDrinkItemInterface {
availableDrinkItems = structuredClone(availableBreakfastDrinkItems);
drinksItem = new DrinksItem();
reset() {
this.drinksItem = new DrinksItem();
}
addDrink({ drink, size, addIn } = {}) {
const options = { drink: false, size: 'Regular', addIn: false, ...arguments[0] };
if (drink && !this.availableDrinkItems.drinks.includes(options.drink)) {
console.log("We're all out or that type of drink does not exist:", options.drink);
return this;
}
if (options.addIn && !this.availableDrinkItems.addIns.includes(options.addIn)) {
console.log("We're all out or that type of add-in does not exist:", options.addIn);
return this;
}
if (!this.drinksItem.drinks[options.drink]) {
this.drinksItem.drinks[options.drink] = {};
}
if (!this.drinksItem.drinks[options.drink][options.size]) {
this.drinksItem.drinks[options.drink][options.size] = {};
}
if (this.drinksItem.drinks[options.drink][options.size][options.addIn]) {
this.drinksItem.drinks[options.drink][options.size][options.addIn] += 1;
} else {
this.drinksItem.drinks[options.drink][options.size][options.addIn] = 1;
}
return this;
}
build() {
return this.drinksItem;
}
}
class LunchItemBuilder extends LunchItemInterface {
availableItems = structuredClone(availableLunchItems);
burger = new LunchItem();
// used to reset BurgerProduct state to its default state
// so that a new burger can be made from scratch
reset() {
this.burger = new LunchItem();
}
addName(burger) {
this.burger.name = burger;
return this;
}
addBun(bun) {
if (this.availableItems.buns.includes(bun)) {
this.burger.bun = bun;
return this;
} else {
console.log("That type of bun does not exist", bun);
}
}
addPatty(patty) {
if (this.availableItems.patties.includes(patty)) {
this.burger.currentItemPatties.push(patty);
return this;
} else {
console.log("That type of patty does not exist", patty);
}
}
addTopping(topping) {
if (this.availableItems.toppings.includes(topping)) {
this.burger.currentItemToppings.push(topping);
return this;
} else {
console.log("We're all out or that type of topping does not exist", topping);
}
}
addSauce(sauce) {
if (this.availableItems.sauces.includes(sauce)) {
this.burger.currentItemSauces.push(sauce);
return this;
} else {
console.log("We're all out or that type of sauce does not exist", sauce);
}
}
addNapkin() {
this.burger.napkins = true;
return this;
}
build() {
const builtBurger = this.burger;
this.reset();
return builtBurger;
}
}
class LunchSideBuilder extends LunchSideItemInterface {
availableSideItems = structuredClone(availableLunchSideItems);
sidesItem = new SidesItem();
reset() {
this.sidesItem = new SidesItem();
}
addSide({ side, size } = {}) {
const options = { side: false, size: 'Regular', ...arguments[0] };
if (!this.availableSideItems.sides.includes(options.side)) {
console.log("We're all out or this type of side does not exist", options.side);
return this;
}
if (!this.sidesItem.sides[options.side]) {
this.sidesItem.sides[options.side] = {};
}
if (this.sidesItem.sides[options.side][options.size]) {
this.sidesItem.sides[options.side][options.size] += 1;
} else {
this.sidesItem.sides[options.side][options.size] = 1;
}
return this;
}
addSauce(sauce) {
if (!this.availableSideItems.sauces.includes(sauce)) {
console.log("We're all out or that type of sauce does not exist", sauce);
return this;
}
if (!this.sidesItem.sides[sauce]) {
this.sidesItem.sides[sauce] = 1;
} else {
this.sidesItem.sides[sauce] += 1;
}
return this;
}
build() {
return this.sidesItem;
}
}
class LunchDrinkBuilder extends LunchDrinkItemInterface {
availableDrinkItems = structuredClone(availableLunchDrinkItems);
drinksItem = new DrinksItem();
reset() {
this.drinksItem = new DrinksItem();
}
addDrink({ drink, size, addIn } = {}) {
const options = { drink: false, size: 'Regular', addIn: false, ...arguments[0] };
if (options.drink && !this.availableDrinkItems.drinks.includes(options.drink)) {
console.log("We're all out or that type of drink does not exist:", options.drink);
return this;
}
if (options.addIn && !this.availableDrinkItems.addIns.includes(options.addIn)) {
console.log("We're all out or that type of add-in does not exist:", options.addIn);
return this;
}
if (!this.drinksItem.drinks[options.drink]) {
this.drinksItem.drinks[options.drink] = {};
}
if (!this.drinksItem.drinks[options.drink][options.size]) {
this.drinksItem.drinks[options.drink][options.size] = {};
}
if (options.addIn) {
this.drinksItem.drinks[options.drink][options.size]['addIn'] = options.addIn;
}
return this;
}
build() {
return this.drinksItem;
}
}
// #endregion Concrete Builders
//#region Directors
class BreakfastItemDirector {
makeChickenMcMuffin(builder) {
builder.addName('Chicken McMuffin');
builder.addBread('English Muffin');
builder.addProtein('Chicken');
builder.addTopping('Lettuce');
builder.addSauce('Mayo');
return builder.build();
}
makePlainBagel(builder) {
builder.addName('Plain Bagel With Butter');
builder.addBread('Plain Bagel');
builder.addButter();
return builder.build();
}
makeSesameBagel(builder) {
builder.addName('Sesame Bagel With Regular Cream Cheese');
builder.addBread('Sesame Bagel');
builder.addCreamCheese();
return builder.build();
}
makeBreakfastBurrito(builder) {
builder.addName('Breakfast Burrito');
builder.addBread('Tortilla');
builder.addProtein('Sausage');
builder.addProtein('Egg');
builder.addTopping('Cheese');
builder.addTopping('Onion');
builder.addTopping('Pepper');
builder.addSauce('Salsa');
return builder.build();
}
makeHotcakes(builder) {
builder.addName('Hotcakes with Syrup and Butter');
builder.addBread('Hotcakes');
builder.addButter();
builder.addSauce('Syrup');
return builder.build();
}
}
class BreakfastSideDirector {
makeAppleSlices(builder) {
builder.addSide({ side: 'Apple Slices' });
return builder.build();
}
makeHashBrowns(builder) {
builder.addSide({ side: 'Hash Browns' });
return builder.build();
}
reset(builder) {
builder.reset();
}
}
class BreakfastDrinkDirector {
makeCoffee(builder) {
builder.addDrink({ drink: 'Coffee', size: 'Large', addIn: 'Sugar' });
return builder.build();
};
makeTea(builder) {
builder.addDrink({ drink: 'Tea', size: 'Medium', addIn: 'Sugar' });
return builder.build();
};
makeOrangeJuice(builder) {
builder.addDrink({ drink: 'Orange Juice', size: 'Medium' });
return builder.build();
};
makeMilk(builder) {
builder.addDrink({ drink: 'Milk', size: 'Medium' });
return builder.build();
}
reset(builder) {
builder.reset();
}
}
class LunchItemDirector {
makeCheeseBurger(builder) {
builder.addName('Cheeseburger');
builder.addBun('Regular');
builder.addPatty('Burger');
builder.addTopping('Onion');
builder.addTopping('Pickle');
builder.addTopping('Cheese');
builder.addSauce('Mustard');
builder.addSauce('Ketchup');
builder.addNapkin();
return builder.build();
}
makeDoubleCheeseBurger(builder) {
builder.addName('Double Cheeseburger');
builder.addBun('Regular');
builder.addPatty('Burger');
builder.addPatty('Burger');
builder.addTopping('Onion');
builder.addTopping('Pickle');
builder.addTopping('Cheese');
builder.addTopping('Cheese');
builder.addSauce('Mustard');
builder.addSauce('Ketchup');
builder.addNapkin();
return builder.build();
}
makeBigMac(builder) {
builder.addName('Big Mac');
builder.addBun('Three Layer Sesame Seed');
builder.addPatty('Burger');
builder.addPatty('Burger');
builder.addPatty('Burger');
builder.addTopping('Lettuce');
builder.addTopping('Onion');
builder.addTopping('Pickle');
builder.addTopping('Cheese');
builder.addSauce('Big Mac Sauce');
builder.addNapkin();
return builder.build();
}
makeMcChicken(builder) {
builder.addName('McChicken');
builder.addBun('Sesame Seed');
builder.addPatty('Chicken');
builder.addTopping('Lettuce');
builder.addSauce('Mayo');
builder.addNapkin();
return builder.build();
}
makeFiletOFish(builder) {
builder.addName('Filet-o-Fish');
builder.addBun('Steamed');
builder.addPatty('Fish');
builder.addTopping('Cheese');
builder.addSauce('Tartar Sauce');
builder.addNapkin();
return builder.build();
}
}
class LunchSideDirector {
makeFries(builder) {
builder.addSide({ side: 'Fries', size: 'Small' });
builder.addSauce('Ketchup');
builder.addSauce('Mayo');
return builder.build();
}
makeOnionRings(builder) {
builder.addSide({ side: 'Onion Rings', size: 'Medium' });
return builder.build();
}
makeChickenSalad(builder) {
builder.addSide({ side: 'Chicken Salad', size: 'Large' });
builder.addSauce('Ranch');
return builder.build();
}
reset(builder) {
builder.reset();
}
}
class LunchDrinkDirector {
makeCoke(builder) {
builder.addDrink({ drink: 'Coke' });
return builder.build();
};
makePepsi(builder) {
builder.addDrink({ drink: 'Pepsi' });
return builder.build();
};
makeSprite(builder) {
builder.addDrink({ drink: 'Sprite' });
return builder.build();
};
makeOrangeCrush(builder) {
builder.addDrink({ drink: 'Orange Crush', size: 'Large', addIn: 'Ice' });
return builder.build();
};
reset(builder) {
builder.reset();
}
}
class BreakfastComboDirector {
constructor() {
this.itemBuilder = new BreakfastItemBuilder();
this.sideBuilder = new BreakfastSideBuilder();
this.drinkBuilder = new BreakfastDrinkBuilder();
this.itemDirector = new BreakfastItemDirector();
this.sideDirector = new BreakfastSideDirector();
this.drinkDirector = new BreakfastDrinkDirector();
}
makeChickenMcMuffinCombo() {
const item = this.itemDirector.makeChickenMcMuffin(this.itemBuilder);
const side = this.sideDirector.makeAppleSlices(this.sideBuilder);
const drink = this.drinkDirector.makeCoffee(this.drinkBuilder);
return { item, side, drink };
};
makePlainBagelCombo() {
const item = this.itemDirector.makePlainBagel(this.itemBuilder);
const side = this.sideDirector.makeHashBrowns(this.sideBuilder);
const drink = this.drinkDirector.makeTea(this.drinkBuilder);
return { item, side, drink };
};
makeSesameBagelCombo() {
const item = this.itemDirector.makeSesameBagel(this.itemBuilder);
const drink = this.drinkDirector.makeOrangeJuice(this.drinkBuilder);
return { item, side, drink };
};
makeBreakfastBurritoCombo() {
const item = this.itemDirector.makeBreakfastBurrito(this.itemBuilder);
const side = this.sideDirector.makeHashBrowns(this.sideBuilder);
const drink = this.drinkDirector.makeCoffee(this.drinkBuilder);
return { item, side, drink };
};
makeHotcakesCombo() {
const item = this.itemDirector.makeHotcakes(this.itemBuilder);
const side = this.sideDirector.makeAppleSlices(this.sideBuilder);
const drink = this.drinkDirector.makeCoffee(this.drinkBuilder);
return { item, side, drink };
};
}
class LunchComboDirector {
constructor() {
this.itemBuilder = new LunchItemBuilder();
this.sideBuilder = new LunchSideBuilder();
this.drinkBuilder = new LunchDrinkBuilder();
this.itemDirector = new LunchItemDirector();
this.sideDirector = new LunchSideDirector();
this.drinkDirector = new LunchDrinkDirector();
}
makeCheeseBurgerCombo() {
const item = this.itemDirector.makeCheeseBurger(this.itemBuilder);
const side = this.sideDirector.makeFries(this.sideBuilder);
const drink = this.drinkDirector.makeCoke(this.drinkBuilder);
return { item, side, drink };
}
makeDoubleCheeseBurgerCombo() {
const item = this.itemDirector.makeDoubleCheeseBurger(this.itemBuilder);
const side = this.sideDirector.makeOnionRings(this.sideBuilder);
const drink = this.drinkDirector.makePepsi(this.drinkBuilder);
return { item, side, drink };
}
makeBigMacCombo() {
const item = this.itemDirector.makeBigMac(this.itemBuilder);
const side = this.sideDirector.makeChickenSalad(this.sideBuilder);
const drink = this.drinkDirector.makeSprite(this.drinkBuilder);
return { item, side, drink };
}
makeMcChickenCombo() {
const item = this.itemDirector.makeMcChicken(this.itemBuilder);
const side = this.sideDirector.makeOnionRings(this.sideBuilder);
const drink = this.drinkDirector.makeOrangeCrush(this.drinkBuilder);
return { item, side, drink };
}
makeFiletOFishCombo() {
const item = this.itemDirector.makeFiletOFish(this.itemBuilder);
const side = this.sideDirector.makeOnionRings(this.sideBuilder);
const drink = this.drinkDirector.makeSprite(this.drinkBuilder);
return { item, side, drink };
}
}
// #endregion Directors
//#region Client Code
console.log("----------------Premade Breakfast Combos----------------");
const breakfastComboDirector = new BreakfastComboDirector();
const breakFastCombo = breakfastComboDirector.makeBreakfastBurritoCombo();
console.log('Breakfast Combo:', JSON.stringify(breakFastCombo, null, 2));
console.log("----------------Custom Breakfast Combos----------------");
const breakfastItemBuilder = new BreakfastItemBuilder();
const breakFastSideBuilder = new BreakfastSideBuilder();
const breakfastDrinkBuilder = new BreakfastDrinkBuilder();
const breakfastItemDirector = new BreakfastItemDirector();
const breakfastSideDirector = new BreakfastSideDirector();
const breakfastDrinkDirector = new BreakfastDrinkDirector();
const hotCakes = breakfastItemDirector.makeHotcakes(breakfastItemBuilder);
let sides = breakfastSideDirector.makeAppleSlices(breakFastSideBuilder);
sides = breakfastSideDirector.makeHashBrowns(breakFastSideBuilder);
sides = breakfastSideDirector.makeHashBrowns(breakFastSideBuilder);
breakfastSideDirector.reset(breakFastSideBuilder);
let drinks = breakfastDrinkDirector.makeCoffee(breakfastDrinkBuilder);
drinks = breakfastDrinkDirector.makeTea(breakfastDrinkBuilder);
breakfastDrinkDirector.reset(breakfastDrinkBuilder);
console.log(JSON.stringify(hotCakes, null, 2));
console.log(JSON.stringify(sides, null, 2));
console.log(JSON.stringify(drinks, null, 2));
console.log("----------------Using Builders Directly----------------");
// Just like we did in the original code example, we
// can also use the builders directly to create combos
// or single items such as a burger, side or drink
const hashBrownOnly = breakFastSideBuilder
.addSide({ side: 'Hash Browns' })
.build();
breakFastSideBuilder.reset();
const largeFliesOnly = breakFastSideBuilder
.addSide({ side: 'Fries', size: 'Large' })
.build();
breakFastSideBuilder.reset();
console.log('hashBrownOnly', JSON.stringify(hashBrownOnly, null, 2));
console.log('largeFliesOnly', JSON.stringify(largeFliesOnly, null, 2));
console.log("----------------Premade Lunch Combos----------------");
const lunchComboDirector = new LunchComboDirector();
const lunchCombo = lunchComboDirector.makeFiletOFishCombo();
console.log('lunchCombo', JSON.stringify(lunchCombo, null, 2));
console.log("----------------Custom Lunch Combos----------------");
const lunchItemBuilder = new LunchItemBuilder();
const lunchSideBuilder = new LunchSideBuilder();
const lunchDrinkBuilder = new LunchDrinkBuilder();
const lunchItemDirector = new LunchItemDirector();
const lunchSideDirector = new LunchSideDirector();
const lunchDrinkDirector = new LunchDrinkDirector();
const bigMac = lunchItemDirector.makeBigMac(lunchItemBuilder);
let lunchSides = lunchSideDirector.makeFries(lunchSideBuilder);
lunchSides = lunchSideDirector.makeFries(lunchSideBuilder);
lunchSideBuilder.reset();
let lunchDrinks = lunchDrinkDirector.makeOrangeCrush(lunchDrinkBuilder);
lunchDrinkBuilder.reset();
console.log(JSON.stringify(bigMac, null, 2));
console.log(JSON.stringify(lunchSides, null, 2));
console.log(JSON.stringify(lunchDrinks, null, 2));
console.log("----------------Using Builders Directly----------------");
// Just like we did in the original code example, we
// can also use the builders directly to create combos
// or single items such as a burger, side or drink
const largeFries = lunchSideBuilderf
.addSide({ side: 'Fries', size: 'Large' })
.addSauce('Ketchup')
.addSauce('Mayo')
.build();
lunchSideBuilder.reset();
const mediumOrangeCrush = lunchDrinkBuilder
.addDrink({ drink: 'Orange Crush', size: 'Medium', addIn: 'Ice' })
.build();
lunchDrinkBuilder.reset();
console.log('largeFries', JSON.stringify(largeFries, null, 2));
console.log('mediumOrangeCrush', JSON.stringify(mediumOrangeCrush, null, 2));
// #endregion Client Code
Also see: Tab Triggers