Feedback for Dungeon Crawler challenge

I am making progress with the Dungeon crawler challenge by writing a combat text app to start with. I figured out how to use modules properly to import game objects thus helping with code separation. My question is mainly around how to prevent player damage from doing more damage than intended when updating the each message state in a tick() function at 1 second intervals? For more info check out my Github repo:

AFAIK I should be getting the same damage value returned because both functions are identical except for the player and enemy objects (which do the same damage by the way) I’m passing in to the functions:

// Player.js
const player = {
   classname: 'dragonknight',
   first: 'Jorvund',
   last: 'Greymane',
   skill: 'flame',
   health: 100,
   xp: 0,
   str: 2,
   dex: 1,
   mag: 1,
   armour: {
      rating: 0
   },
   weapon: {
      name: 'greatsword',
      damage: 10
   },
   power: {
      name: 'searing strike',
      damage: 20   
   }   
};
export default player;
// App.js
playerDealsDamage(pc, npc) {
   let amount = pc.weapon.damage;
   if(this.player.health <= 0) {
      return this.getFullName(pc) + ' is dead';
   } else if (pc.health > 0){
      this.enemy.health -= amount;
      return 'total damage : ' + amount.toString();
   } else {
      return this.kill(npc);
   }
}
enemyDealsDamage(pc, npc){
   let amount = npc.weapon.damage;
   if(this.enemy.health <= 0) {
      return this.getFullName(npc) + ' is dead';
   } else if (pc.health > 0){
      this.player.health -= amount;
      return 'total damage: ' + amount.toString();
   } else {
      return this.kill(pc);
   }
}
1 Like

Hello, I’m updating your category to JavaScript. It doesn’t appear that you provide a link for feedback, but need help with an issue.

I figured out what the problem was. I wasn’t checking for max health when either the player does damage to the enemy or vice versa then escaping out of that function if damage was dealt.