Cannot read property 'isBound' of undefined
January 11, 2019 at 3:25pmCannot read property 'isBound' of undefined
January 11, 2019 at 3:25pm (Edited 3 years ago by @olistic)I am just starting to learn javascript. I am working on Warrior JS now. I have this code here. It runs fine with forward. However with backwards I get:
Error: Cannot read property 'isBound' of undefined
.
This seems to occur when warrior.rescue()
is changed to warrior.rescue('backward')
. So if I leave everything forward but that I can replicate the problem that way too.
I know the code isn't finished but I am trying to understand the error and where it is coming from. I am on Baby Steps Level 6 so I don't have warrior.pivot()
yet.Any insight would be great. Thanks.
class Player {constructor() {this.health = 20;this.lastHealth = 20;this.direction = 'forward';}playTurn(warrior) {if (warrior.feel(this.direction).isEmpty()) {this.walkorRest(warrior);} else {this.rescueOrAttack(warrior);}this.lastHealth = warrior.health();}isUnderAttack(warrior) {return warrior.health() < this.lastHealth;}fullHealth(warrior) {return warrior.health() === warrior.maxHealth();}walkorRest(warrior) {if (this.isUnderAttack(warrior) || this.fullHealth(warrior)) {warrior.walk(this.direction);} else {warrior.rest();}}rescueOrAttack(warrior) {if (!warrior.feel(this.direction).isEmpty()) {if (warrior.feel(this.direction).getUnit().isBound()) {warrior.rescue(this.direction);} else {warrior.attack();}}}}