Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Foundations Objects Prototypes

Mark Bradshaw
PLUS
Mark Bradshaw
Courses Plus Student 7,658 Points

Still can't get throughh a javascript quiz question. Please advise.

Here;s the question: Modify the Car's prototype to have 'wheels' set to 4.

Here's the code before my answer: <script> var carPrototype = { model: "generic", currentGear: 0, increaseGear: function() { this.currentGear ++; }, decreaseGear: function() { this.currentGear--; } } function Car(model) { this.model = model; } Here's my answer to the question: Car.prototype.wheels = 4;

Mark,

You had 2 people trying to help you in your other question about this. You didn't need to double post your question.

1 Answer

Patrick Johnson
Patrick Johnson
9,505 Points

It's asking for the car prototype. Which is the first variable that is created (in this case: var carPrototype). You need to modify that to include the set of wheels any new car created from that prototype will have.

So, the prototype should be:

var carPrototype = { 
    model: "generic", 
    currentGear: 0, 
   // include the wheels here
   wheels: 4,
    increaseGear: function() { this.currentGear ++; }, 
    decreaseGear: function() { this.currentGear--; } 
}

If you wanted to modify your prototype after the fact (lets pretend you forgot to add it originally) you can do this.

carPrototype.wheels = 4;

That way, when you run anything that uses the prototype, it'll inherently have 4 wheels.