Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bonfire: Make a Person: expect(Object.keys(bob).length) to equal 3 instead of 6. #877

Closed
emptyteacup opened this issue Jun 9, 2015 · 2 comments

Comments

@emptyteacup
Copy link

screen shot 2015-06-09 at 4 11 08 pm
When doing this challenge, I passed all the tests except for the one described below:
expect(Object.keys(bob).length).to.eql(6);
I had to add the three blank variables (as indicated by the comments) in order to get the tests to pass so there seems to be a redundancy.
When I ran this on a separate editor with:
console.log(Object.keys(bob));
to see what it was searching for, I got:
[ 'firstAndLast', 'first', 'last'].
Just those three keys were what I needed to pass the tests. Have I failed to follow the instructions and write the program the right way or is this a valid issue?

@BerkeleyTrue
Copy link
Contributor

@emptyteacup Thanks for the notifying us!

Looks like this bonfire is causing a lot of confusion and I think it stems from the tests not being fully fleshed out (darn tests)...

The main point to take away is that I, as a user of the object Person ands its instantiations, should not be able to directly change the first name of bob without using the method setFirstName. But with your implementation I could set bobs name by doing bob.first = 'north' and set his last name by bob.last = 'West'

What the bonfire is looking for is to create variables scoped to the constructor and then create the instance methods in the constructor so they have access to these scoped variables do to closures.

i.e.

Function Person(firstandlast) {
  var firstname = firstandlast.split(' ')[0]; // firstname is scoped to this function and not available outside
  this.setFirstName = function(newFirst) { firstname = newFirst; } // because this function is created in Person constructor it has access to that firstname variable and any other variables declared in this scope.
};

Hope that helps!

@emptyteacup
Copy link
Author

Thanks, I get it now.

This was referenced Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants