I'm new to JavaScript and working on a personal program which creates car objects and stores them in an array, I am having issues with returning all array elements as only the first array element is returned.
const carFactory = {
_cars:[
{
make: 'default',
model: 'default',
year: 0,
}
],
get cars(){
if(this._cars.length > 0 ){
for(let i = 0; i < this._cars.length; i++){
return `Car Make: ${this._cars[i].make} - Car Model: ${this._cars[i].model} Manufacture Year: ${this._cars[i].year}`;
}
}else{
return `Please add car details`;
}
},
addCar(carMake, carModel, carYear){
this._cars.push({
carMake,
carModel,
carYear
})
}
}
carFactory.addCar('Toyota', 'Corolla', 2003);
console.log(carFactory.cars);