Challenge for Object Functions, Constructors and Prototypes
Challenge
Create 10 cars, where each car has a color
and number
. The cars should be numbered in order from 0 to 9. The cars from 0 to 4 should be colored "green" and the cars from 5 to 9 should be colored "blue". Place the cars in order in an array called carGarage
.
Guideline:
To avoid duplicate code when creating 10 separate cars, first first create a constructor function Car
that takes color
and number
parameters and sets them to this.color
and this.number
. Then create 10 cars and place them in a carGarage
array.
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.