Head-First-JavaScript-Programming icon indicating copy to clipboard operation
Head-First-JavaScript-Programming copied to clipboard

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

Open tygamchenry opened this issue 7 years ago • 2 comments

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();

tygamchenry avatar Jul 20 '17 16:07 tygamchenry

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.

bethrobson avatar Jul 20 '17 18:07 bethrobson

Ok, I can wrap my head around that. Thank you for the prompt responses (again)!

Tyga

On Jul 20, 2017 1:29 PM, "Elisabeth Robson" [email protected] wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bethrobson/Head-First-JavaScript-Programming/issues/20#issuecomment-316790656, or mute the thread https://github.com/notifications/unsubscribe-auth/ARggdhr6d162sFvixbIpx3_aLQKsK_X0ks5sP5yAgaJpZM4OeWQd .

tygamchenry avatar Jul 20 '17 18:07 tygamchenry