Challenge: Solution Review
This lesson will explain the solution to the problem from the previous coding challenge.
We'll cover the following...
Solution #
Press + to interact
class Dress{constructor(serialNumber,type,color,designer,availability){this.serialNumber = serialNumberthis.type = typethis.color = colorthis.designer = designerthis.availability = availabilitythis.price = 0}dressPrice(){if(this.type == "maxi"){this.price = 1000}if(this.type == "gown"){this.price = 2000}if(this.type = "skirt"){this.price = 500}return this.price}}class DressFactory {constructor() {this.existingDresses = {}}createDress(serialNumber,type,color, designer, availability) {var exists = this.existingDresses[serialNumber]if (!!exists) {return this.existingDresses[serialNumber]}else {var dress = new Dress(serialNumber,type,color, designer, availability)this.existingDresses[serialNumber]= dressreturn dress}}}const factory = new DressFactory()const pinkdress1 = factory.createDress("#123","skirt","pink","Zara","yes")const pinkdress2 = factory.createDress("#123","skirt","pink","Zara","yes")console.log(pinkdress1 === pinkdress2)console.log(pinkdress1.dressPrice())console.log(pinkdress2.dressPrice())
Explanation
As explained in the ...