This is my first time posting on the forum.
I am having a strange problem which I would like some help with or clarification.
I am using Visual Studio Code to practice my FCC problems, however whenever
I execute the code for this specific exercise I’m getting erratic output.
After creating the instance of my Dog constructor, I display it using the console.log
method just to verify it. I then move on to display the ownProps and prototypeProps
arrays.
However, whenever I console.log the beagle instance, I only get the output for
ownProps array. ‘console.log(prototypeProps)’ is mysteriously omitted.
If I remove the console.log(beagle), both arrays are outputted correctly.
Can anybody explain this behaviour, or is it possibly an issue with Visual Studio Code?
FCC seems to be logging the info correctly.
Your code so far
function Dog(name) {
this.name = name;
}
Dog.prototype.numLegs = 4;
let beagle = new Dog("Snoopy");
console.log(beagle);
let ownProps = [];
let prototypeProps = [];
// Only change code below this line
for (let property in beagle) {
if (Dog.hasOwnProperty(property)) {
ownProps.push(property);
} else {
prototypeProps.push(property);
}
}
console.log(ownProps);
console.log(prototypeProps);
**Your browser information:**
User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36</code>.
**Challenge:** Iterate Over All Properties
**Link to the challenge:**
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/object-oriented-programming/iterate-over-all-properties