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
khcir .
Courses Plus Student 8,527 PointsJavaScript 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
Andrew Shook
31,709 Pointsfunction Car(model) {
this.model = model;
}
Wayne Priestley
19,579 PointsHi 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.
Wayne Priestley
19,579 PointsWOOHOOOOOO!!!!!!
I just figured it out…..
don't replace just add
wheels: 4,
Andrew Shook
31,709 PointsYes 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.
Mohamed Mokhtar
9,651 Pointsi didn't modify carPrototype var , i just add this line of code at the end Car.prototype.wheels = 4; and it worked
khcir .
Courses Plus Student 8,527 PointsYou are a genius, man...
Stephen Burke
7,212 PointsI'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");
Oliver Gibbs
9,771 PointsIt'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.
Wayne Priestley
19,579 PointsI'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.
Andrew Shook
31,709 PointsCan you post more information, like what is the error that its giving you and what is the exact question?
Andrew Shook
31,709 Pointsyou 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;
Wayne Priestley
19,579 PointsIt 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 :)