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

Chapter 13 Robot game solution (p. 583 in pdf book) #20

Open
tygamchenry opened this issue Jul 20, 2017 · 2 comments
Open

Chapter 13 Robot game solution (p. 583 in pdf book) #20

tygamchenry opened this issue Jul 20, 2017 · 2 comments

Comments

@tygamchenry
Copy link

Hello,

Why is a function needed under the unlock function? The following doesn't work... why doesn't it?

Game.prototype.unlock = function() {
if (this.level === 42) {
console.log(this.name + " is blasting you with laser beams.");
}
}

...

robby.unlock();
rosie.unlock();

@bethrobson
Copy link
Owner

because we don't want lasers only at level 42; we want lasers for all robots that reach level 42 so they keep them after that too. By adding the function to the prototype, you can call deployLaser after you've reached level 42 and gone beyond.

@tygamchenry
Copy link
Author

tygamchenry commented Jul 20, 2017 via email

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