Iterate Over All Properties

Iterate Over All Properties
0

#1

Tell us what’s happening:
Not getting it

Your code so far


function Dog(name) {
  this.name = name;
}

Dog.prototype.numLegs = 4;

let beagle = new Dog("Snoopy");

let ownProps = [hr];
let prototypeProps = [];

// Add your code below this line 


for (let property in beagle) {
  if(beagle.hasOwnProperty(property)) {
  ownProps.push(property);
} else {
  prototypeProps.push(property);
}
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/iterate-over-all-properties


#2

Do you have a question?


#3

Yes, how should i solve this ?


#4

Describe to me what you’ve done so far.


#5

Look at the example

for (let property in duck) {
  if(duck.hasOwnProperty(property)) {
    ownProps.push(property);
  } else {
    prototypeProps.push(property);
  }
}

Now look at your code

for (let property in beagle) {
  ownProps.push(property);
} else {
  prototypeProps.push(property);
  }
}

Something isn’t the same.


#6

I updated my code by adding for (let property in beagle) { if(beagle.hasOwnProperty(property)) { ownProps.push(property); } else { prototypeProps.push(property); } }

But it’s showing hr is not defined


#7

If you did not modify and code above the line which shows // Add your code below this line and only added the code you show above, it should pass the challenge. You may need to refresh the page or try a different browser.


#8

Okay,all you need to do is delete “hr” in [].