menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

WarriorJS

An exciting game of programming and Artificial Intelligence

Channels
Team

Level 4 Invalid submitted code: cannot read property 'health'

August 17, 2018 at 10:00pm

Level 4 Invalid submitted code: cannot read property 'health'

August 17, 2018 at 10:00pm
class Player {
constructor() {
this._health = 20;
}
playTurn(warrior) {
// TODO: Add missing condition
if (
warrior.feel().isEmpty() &&
!this.isUnderAttack() &&
!this.isInjured()
) {
warrior.walk();
} else if (!warrior.feel().isEmpty()) {
warrior.attack();
} else {
}
// TODO: Update this._health with warrior.health
this._health = warrior.health();
}
isInjured(warrior) {
// TODO: Return false if warrior health is less than 20
return warrior.health() < 20;
}
isUnderAttack(warrior) {
// TODO: Compare this._health with warrior.health()
return this._health < warrior.health();
}
}
Can someone give me a hint please

October 5, 2018 at 7:41pm
From what it looks like, you're calling isUnderAttack and isInjured but you aren't passing the warrior object to them.