# Bug in iterate over all properties

**URL:** <https://forum.freecodecamp.org/t/bug-in-iterate-over-all-properties/440230>\
**Category:** freeCodeCamp Support\
**Created:** [January 12, 2021, 2:32pm UTC](https://forum.freecodecamp.org/t/bug-in-iterate-over-all-properties/440230 "2021-01-12T14:32:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarachan](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/amarachan/32/81700_2.png) [@amarachan](https://forum.freecodecamp.org/u/amarachan)\
**Post date:** [January 12, 2021, 2:32pm UTC](https://forum.freecodecamp.org/t/bug-in-iterate-over-all-properties/440230/1 "2021-01-12T14:32:48Z")

</div>

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/object-oriented-programming/iterate-over-all-properties)**
>
> Learn to Code — For Free

i guess there is a bug in this challenge because it should show error when i run tests but instead it shows success as you can see the code and output in console log even though i know i should use else statement to get desired output but the tests ran successful even with wrong code and wrong output

 ![Screenshot_2021-01-12 freeCodeCamp org](https://global.discourse-cdn.com/freecodecamp/original/3X/0/d/0df54e8e8338b3f10a8eecc7f4e238995a55014a.png)

```auto

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

Dog.prototype.numLegs = 4;

let beagle = new Dog("Snoopy");

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

// Only change code below this line
for(let own in beagle){
  if(beagle.hasOwnProperty(own)){
    ownProps.push(own);                   
  } prototypeProps.push(own);                 
}
console.log(prototypeProps,ownProps)

==>>> // this gives an output of ['name', 'numLegs'] ['name'] 

```

//correct code below

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

Dog.prototype.numLegs = 4;

let beagle = new Dog("Snoopy");

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

// Only change code below this line
for(let own in beagle){
  if(beagle.hasOwnProperty(own)){
    ownProps.push(own);
  }else {
  prototypeProps.push(own);
}
}
console.log(prototypeProps,ownProps)

==>>> // this gives an output of ['numLegs'] ['name'] 

```

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [January 12, 2021, 2:36pm UTC](https://forum.freecodecamp.org/t/bug-in-iterate-over-all-properties/440230/2 "2021-01-12T14:36:06Z")

</div>

Please provide the full code to replicate the issue. Screenshots are very difficult to work with.

* * *

Thank you for helping make FCC better. Bugs can be reported as [GitHub Issues](https://github.com/freeCodeCamp/freeCodeCamp/issues). Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

---

<div class="post-metadata">

**Author:** ![lasjorg](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lasjorg/32/280761_2.png) [@lasjorg](https://forum.freecodecamp.org/u/lasjorg)\
**Post date:** [January 12, 2021, 5:53pm UTC](https://forum.freecodecamp.org/t/bug-in-iterate-over-all-properties/440230/3 "2021-01-12T17:53:59Z")

</div>

I opened an issue for this.

> <https://github.com/freeCodeCamp/freeCodeCamp/issues/40682>
>
> Challenge: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/object-oriented-programming/iterate-over-all-properties
> Forum: https://forum.freecodecamp.org/t/bug-in-iterate-over-all-properties/440230
> Right now you can pass the challenge using a for loop with no conditionals.
> for (let property in beagle) {
> ...

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [July 14, 2021, 5:54am UTC](https://forum.freecodecamp.org/t/bug-in-iterate-over-all-properties/440230/4 "2021-07-14T05:54:06Z")

</div>

Closed on July 14, 2021, 5:54am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
