Challenge: Solution Review
This lesson will explain the solution to the problem from the previous coding challenge.
We'll cover the following...
We'll cover the following...
Solution #
Explanation
The task was to create a function createToy, which instantiated either a ToyDuck or a ToyCar object.
We start by defining the constructor functions. Let’s take a look at them.
-
ToyDuckfunction ToyDuck(toyObj){ this.color = toyObj.color; this.price = toyObj.price; }It accepts a parameter
toyObj, that is, the “toy object”, sets itscolorequal totoyObj.colorand itspriceequal totoyObj.price. -
ToyCarfunction