In this exercise we explored some of the differences between how classes are defined in Java and JavaScript. Used a car dealership format and created the classes, including their properties and behaviours, using JavaScript.
Created project from scratch and installed dependencies (hint: npm install -D jest).
- Created
Carclass. The car has properties representing manufacturer, price and engine type. - Set up Jest and wrote tests to ensure accessibility to each of the properties in a
Carobject. - Created a
Dealershipclass. It contains properties representing its name, maximum number of cars it has and the cars currently in stock. - Added methods to
Dealershipto:- Counted the number of cars in stock
- Added a car to stock
- Returned an array containing each car's manufacturer
- Found all the cars from a given manufacturer
- Found the total value of all the cars in stock
- Wrote tests for
Dealership's methods.