Javascript Objects code snippet confirmation

Found a piece of code snippet, real basic code on JS relating to objects. Wanted to know what the issue is with this, please.

//code below//
function Dog(name) { = name;
  this.bark = function() {
var dog = new Dog("Baxter");
//code above//
  • You have a function Dog that creates an object of the type Dog (that is what the new Dog is doing).
  • it takes one argument and sets the name property on the new object to that.
  • so you do new Dog('Baxter'), and you get an object like:
  name: 'Baxter'
  • there is also a function attached to that object (bark) but it doesn’t do anything.
var dog = new Dog('Spot')
// 'Spot'
// undefined
// bark does nothing
  • you are also console.log-ing the string ‘Woof’, but that has nothing to do with the Dog object.

I assume you’re supposed to be modifying the bark function. At the minute there is nothing actually wrong with the code: new Dog('Baxter') creates an object with property name (with the value ‘Baxter’), and a property bark which does nothing.

thanx man, I understand…
but is the code in correct format, like how its ordered? or are there some things that I must rearrange?

As I say, the code is correct, it works, there are no syntax errors or anything, but you havent said whether there’s some task you’re supposed to do with it, to change it. At the minute, bark does nothing - I assume the task is to change that, but I have no way of knowing

Yea, I get you…nah it was just because, I got the code snippet from mimo and I wanted to find out if it works or if they’re are no syntax errors.
But thanx for your patience man…much appreciated.

I have the same issue, did you finally get the answer ? :slight_smile:

If you have an issue with a challenge use the Ask for help button inside it. As said before the code is syntactically correct but without knowing what the goal is it is not possible to know if the logic is correct