# Make a Person - Algorithm Challenge

**URL:** <https://forum.freecodecamp.org/t/make-a-person-algorithm-challenge/138203>\
**Category:** General\
**Created:** [July 25, 2017, 4:21pm UTC](https://forum.freecodecamp.org/t/make-a-person-algorithm-challenge/138203 "2017-07-25T16:21:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pthorup](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pthorup/32/44179_2.png) [@pthorup](https://forum.freecodecamp.org/u/pthorup)\
**Post date:** [July 25, 2017, 4:21pm UTC](https://forum.freecodecamp.org/t/make-a-person-algorithm-challenge/138203/1 "2017-07-25T16:21:11Z")

</div>

I’m doing the Make a Person challenge and just can’t debug my solution and understand where I’m going wrong. After some exhausting hours, I decided to check the spoiler alert 😥 I see its similar but they put the splitting of the full name in both the set and get methods. Why can’t I not have it as a local variable?

Here is my code:

```
    function Person(firstAndLast) {
      
        this.sFullName = firstAndLast;
        var aNames = firstAndLast.split(' ');
     
        this.sFirstName = aNames[0];
        this.sLastName = aNames[1];

      
        // Setters
        this.setFirstName = function(sFirstName){
            this.sFirstName = sFirstName;
        };
        this.setLastName = function(sLastName){
            this.sLastName = sLastName;
        };
        this.setFullName = function(sFullName){
            this.sFullName = sFullName;
        };
        
      
        // Getters
        this.getFirstName = function() {
            return this.sFirstName;
        }; 
        this.getLastName = function() {
            return this.sLastName;
        };
        this.getFullName = function() {
            return this.sFullName;
        }; 
        
    }

    var bob = new Person('Bob Ross');
```

---

<div class="post-metadata">

**Author:** ![Matthew-Keating](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Matthew-Keating](https://forum.freecodecamp.org/u/Matthew-Keating)\
**Post date:** [July 25, 2017, 4:40pm UTC](https://forum.freecodecamp.org/t/make-a-person-algorithm-challenge/138203/2 "2017-07-25T16:40:57Z")

</div>

Too many keys.

```auto
let bob = new Person("Bob Ross");
console.log(Object.keys(bob).length) // 9 should be 6!

```

```auto
    function Person(firstAndLast) {
      
        this.sFullName = firstAndLast; // 1 Assigning firstAndLast to key sFullName of this.
        var aNames = firstAndLast.split(' '); // local variable in scope Person doesn't count as key but can be accessed by functions through closure.
     
        this.sFirstName = aNames[0]; // 2
        this.sLastName = aNames[1];// 3

      
        // Setters
        this.setFirstName = function(sFirstName){ // 4
            this.sFirstName = sFirstName;
        };
        this.setLastName = function(sLastName){ // 5
            this.sLastName = sLastName;
        };
        this.setFullName = function(sFullName){ // 6
            this.sFullName = sFullName;
        };
        
      
        // Getters
        this.getFirstName = function() { // 7
            return this.sFirstName;
        }; 
        this.getLastName = function() { // 8
            return this.sLastName;
        };
        this.getFullName = function() { // 9
            return this.sFullName;
        }; 
        
    }

```

They want you to learn how closure works.

---

<div class="post-metadata">

**Author:** ![pthorup](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pthorup/32/44179_2.png) [@pthorup](https://forum.freecodecamp.org/u/pthorup)\
**Post date:** [July 25, 2017, 4:59pm UTC](https://forum.freecodecamp.org/t/make-a-person-algorithm-challenge/138203/3 "2017-07-25T16:59:08Z")

</div>

Oh ok. Yea, I didn’t get the key part they were asking. Thanks for clearing things up.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:47pm UTC](https://forum.freecodecamp.org/t/make-a-person-algorithm-challenge/138203/4 "2021-01-17T20:47:26Z")

</div>

Closed on January 17, 2021, 8:47pm UTC


