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

http://teamtreehouse.com/library/prototypes

hi there!

i m stack and cant figure out the solution for this challenge, any help will be much appreciated...

here is my code so far...

  function Car() {
   this.currentGear = currentGear;
  }
     Car.prototype = carPrototype;
  generic = new Car("generic");

7 Answers

function Car(model) {
                    this.model = model;
      }

Hi Andrew,

Q. Modify the Car's prototype to have 'wheels' set to 4.

<h1>JavaScript Foundations</h1>
    <h2>Objects: Prototypes</h2>
    <script>


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

I'm trying to insert

wheels = ("4")

but all i get is " task 1 is no longer passing or task 2 is no longer passing". I've been stuck on this for more than an hour now.

WOOHOOOOOO!!!!!!

I just figured it out…..

don't replace just add

wheels: 4,

Yes they problem you where having is that you were using the wrong syntax to set the property of an object. When you set the value of a property you use a colon instead of an equal sign.

i didn't modify carPrototype var , i just add this line of code at the end Car.prototype.wheels = 4; and it worked

You are a genius, man...

I'm very confused on part 3. Can someone help me out? This is what I have so far:

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

  function Car (model) {
                this.model = model;
  }

  Car.prototype = carPrototype;

  wheels = new Car ("4");

It's asking you to modify the actual carPrototype itself, so you'd need to remove the last bit above where you've put wheels = new Car ("4"); And figure out where to add that information into the var carPrototype block above.

I'm very very stuck on task 3 of 3.

I just can't figure out where to make the changes to my code without breaking one of the previous tasks.

its 3.40 am and i would really like to get this done so i can go to bed.

help would be appreciated please.

Can you post more information, like what is the error that its giving you and what is the exact question?

you need to go to "var carPrototype" object at the top of the <script> and add the property "wheel: 4," That sound be all you have to do. Your code should look something like this: var carPrototype = { model: "generic", currentGear: 0, increaseGear: function() { this.currentGear ++; }, decreaseGear: function() { this.currentGear--; }, wheel: 4, }

  function Car(model) {
            this.model = model;
  }
  Car.prototype = carPrototype;

It took so long to figure that out, i think i got more confused the longer i tried, should of asked for help sooner.

Cheers Andrew, its all over now :)