In this exercise, you'll be creating a Bakery class using JavaScript. This class will represent a bakery and have some properties and methods to track the bakery's location, the number of cakes in stock, and the ability to bake cakes.
Create a Bakery class with these properties and methods:
- property
location: this property represents the specific location of each bakery (each instance of the bakery class can have a different location). - property
brandName: this property will represent the name of the brand. It will be the same for all bakeries. - method
printLocation: this method should display the location of the bakery (when you call this method, it will show the location of the bakery).
We will add functionality to bake cakes & keep track of the number of cakes we have:
- Add a property
amountOfCakes: this property represents the number of cakes that we have in stock. The initial value should be zero (when a bakery is created, it starts with zero cakes). - Create a method
printAmountOfCakes: this method should display the current number of cakes in stock. - Create a method
makeCake: each time you call this method, it will increase the number of cakes in stock by 1. After baking a cake, the method should automatically display the updated number of cakes (reuse the function that you already have).
- Add a property
cash, were we will keep information about the money that we have (initial value: 0) - Add functionality to display the money we have
- Add functionality to sell one cake (decrease stock by 1 & increases money by 3)
- We shouldn't sell a cake if we don't have cakes, right? When a cake is sold, make sure there's actually stock ;)
Let's apply some real life economics...
- Every time a new cake is created, it costs 1 (deducted from the cash available)
- Every time a cake is sold, you collect 3
- You can not make new cakes if there's no money
- Initial cash: 2 (we need some initial investment, otherwise we can not start making cakes :p)
Solution: https://stackblitz.com/edit/js-kftsnf?file=index.js
