JSFiddle - React, Tailwind, and code Playground
JavaScript
/* A constructor for defining new vehicle shops */
var VehicleShop = function() {};
VehicleShop.prototype = {
sellVehicles: function(options) {
var vehicle;
switch(options.vehicleType) {
case 'Car':
vehicle = new Car(options);
break;
case 'Truck':
vehicle = new Truck(options);
break;
}
vehicle.inspect();
vehicle.wash();
vehicle.transfer();
return vehicle;
}
};
/* A constructor for defining new cars */
function Car(options) {
// default configurations
this.brand = options.brand || 'Mercedes-Benz';
this.gearbox = options.gearbox || 'Automatic';
this.fuelType = options.fuelType || 'Petrol';
};
Car.prototype = {
inspect: function() {
return console.log('This car has passed the inspection. Detailed car information: Manufacturer - ' + this.brand + ', Gearbox - ' + this.gearbox + ', Fuel Type - ' + this.fuelType + '.');
},
wash: function() {
return console.log('This car has been washed!');
},
transfer: function() {
return console.log('The ownership of this car has been successfully updated! It is now registered under your name.');
}
};
/* A constructor for defining new trucks */
function Truck(options) {
// default configurations
this.brand = options.brand || 'Ford';
this.gearbox = options.gearbox || 'Manual';
this.fuelType = options.fuelType || 'Diesel';
this.wheelSize = options.wheelSize || '22.5';
};
Truck.prototype = {
inspect: function() {
return console.log('This truck has passed the inspection. Detailed truck information: Manufacturer - ' + this.brand + ', Gearbox - ' + this.gearbox + ', Fuel Type - ' + this.fuelType + ', Wheel Size: ' + this.wheelSize + '.');
},
wash: function() {
return console.log('This truck has been washed!');
},
transfer: function() {
return console.log('The...