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

Jacob Tennyson
Jacob Tennyson
6,240 Points

Challenge Task 1 Modify the 'Car' constructor function so that it takes an argument for its model and set its 'mod

I really don't understand this?

<!DOCTYPE html>
<html lang="en">
    <title> JavaScript Foundations: Objects</title>
      html {
        background: #FAFAFA;
        font-family: sans-serif;
    <h1>JavaScript Foundations</h1>
    <h2>Objects: Prototypes</h2>

      var carPrototype = {
        model: "generic",
        currentGear: 0,
        increaseGear: function() {
          this.currentGear ++;
        decreaseGear: function() {

      function Car() {



1 Answer

Hey Jacob Tennyson,

The Car() function is setting up a constructor so that additional objects that have the prototype of carPrototype can be added. What you are doing is setting up the object to take in a new model value to replace the "generic" value within the default prototype. And since we don't know exactly what the new car is going to be called, we can use the this keyword to change the model for this car to the model variable we receive. You can use the "model" variable name twice with two different modes of functionality, because the left side of the equation is going to be the key "model" and the right side is going to be the variable placeholder "model" that you set inside the function.

I don't want to post the answer, because I want you to intuitively grasp the concept that is going on here. But, if you get too frustrated at it, I'll help you further!