question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing Parameters to a Constructor

See original GitHub issue

Challenge Waypoint: Make Unique Objects by Passing Parameters to our Constructor has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

var Car = function() {
  //Change this constructor
  this.wheels = 4;
  this.seats = 1;
  this.engines = 1;
};

//Try it out here
var myCar = new Car(3, 1, 2);

// Only change code above this line

(function() {return JSON.stringify(myCar);})();

I only modified the code within the // parameters and no matter the attempt I would get errors. I tried to pass parameters individually and would still receive errors. After asking for help on chat I was able to pass it, but not within the parameters set. I used multiple variations given, but none of them worked within the instructions. The constructor doesn’t appear to be able to be modified as is, the other people stated the same thing. Maybe the instructions weren’t as clear or this could be a bug. Error stated “Calling new Car(3,1,2) should produce an object with a wheels property of 3, a seats property of 1, and an engines property of 2.”

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
aulisiuscommented, Nov 14, 2015

I don’t see what the problem is. The instructions are very clear

Alter the Car constructor to use parameters to assign values to the wheels, seats, and engines properties. Then call your new constructor with three number arguments and assign it to myCar to see it in action.

You need to change the code from

var Car = function() {
  this.wheels = 4;
  this.seats = 1;
  this.engines = 1;
};

to

var Car = function(wheels, seats, engines) {
  this.wheels = wheels;
  this.seats = seats;
  this.engines = engines;
};

and then assign it to var myCar with the constructor.

0reactions
Kristi92commented, Jul 10, 2017

chat room doesn’t help a lot!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing Information to a Method or a Constructor
This method has four parameters: the loan amount, the interest rate, the future value and the number of periods. The first three are...
Read more >
How to pass parameter to constructor [closed] - Stack Overflow
How to pass parameter to constructor [closed] · You can only define the coursebookname variable one time (which is when you specify the...
Read more >
Passing Information into a Method or a Constructor
Arguments are passed by value. When invoked, a method or a constructor receives the value of the variable passed in. When the argument...
Read more >
4.6.2 Constructors with parameters and defining the == and ...
4.6.2 Constructors with parameters and defining the == and < operators · use objects as parameters of functions and methods (you will see...
Read more >
Passing Parameters to Register — Autofac 6.0.0 documentation
When you register a reflection-based component, the constructor of the type may require a parameter that can't be resolved from the container. You...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found