There is an error in the placement of damageThisRound in the "What you'll be building" section


#1


Dragon Slayer exercise one


In my opinion, there is an error with the default code provided by codecademy. The variable damageThisRound should be placed within the first if statement. If it is not, all "hits" within this game are created equal. There is no recalculating of the damage a hit does when it is placed prior to the if statement. It is simply calculated once, and carried forward for the remainder of the game.

Unless that was oddly intended, it should be:


while (slaying) {
  if (youHit) {
    var damageThisRound = Math.floor(Math.random() * 5 + 1);
    console.log("You hit the dragon and did " + damageThisRound + " damage!");
    totalDamage += damageThisRound;
  }

#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.