From a69150ed731e727516f8fe013bef9fdab6a24786 Mon Sep 17 00:00:00 2001 From: Victor Hugo Date: Wed, 7 Jan 2026 16:48:31 +0000 Subject: [PATCH 1/3] iteration 0 DONE + iteration 1 DONE + iteration 2 DONE --- src/viking.js | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/viking.js b/src/viking.js index 9017bfc8a..69a042130 100755 --- a/src/viking.js +++ b/src/viking.js @@ -1,8 +1,39 @@ // Soldier -class Soldier {} +class Soldier { + constructor(health, strength) { + this.health = health; + this.strength = strength; + } + + attack() { + return this.strength; + } + + receiveDamage(damage) { + this.health -= damage; + } +} // Viking -class Viking {} +class Viking extends Soldier { + constructor(name, health, strength){ + super(health, strength) + this.name = name; + } + + receiveDamage(damage){ + this.health -= damage; + if(this.health > 0){ + return `${this.name} has received ${damage} points of damage` + } else if (this.health <= 0){ + return `${this.name} has died in act of combat` + } + } + + battleCry(){ + return "Odin Owns You All!" + } +} // Saxon class Saxon {} From 17221f406bd1316b52d1afb13141243dec72c7d1 Mon Sep 17 00:00:00 2001 From: Victor Hugo Date: Wed, 7 Jan 2026 18:28:49 +0000 Subject: [PATCH 2/3] iteration 3 DONE + iteration BONUS 4 DONE --- src/viking.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/src/viking.js b/src/viking.js index 69a042130..01a44286b 100755 --- a/src/viking.js +++ b/src/viking.js @@ -36,7 +36,57 @@ class Viking extends Soldier { } // Saxon -class Saxon {} +class Saxon extends Soldier { + receiveDamage(damage){ + this.health -= damage; + if(this.health > 0){ + return `A Saxon has received ${damage} points of damage` + } else if (this.health <= 0){ + return `A Saxon has died in combat` + } + } +} // War -class War {} +class War { + constructor(){ + this.vikingArmy = [] + this.saxonArmy = [] + } + + addViking(vikingObj){ + this.vikingArmy.push(vikingObj); + } + + addSaxon(saxonObj){ + this.saxonArmy.push(saxonObj); + } + + vikingAttack(){ + const lastSaxon = this.saxonArmy[this.saxonArmy.length - 1] + const firstViking = this.vikingArmy[0] + + const vikingAtkSaxon = lastSaxon.receiveDamage(firstViking.attack()); + + if(lastSaxon.health <= 0){ + this.saxonArmy.pop(); + } + + return vikingAtkSaxon; + } + + saxonAttack(){ + const lastViking = this.vikingArmy[this.vikingArmy.length - 1]; + const firstSaxon = this.saxonArmy[0]; + + const saxonAtkViking = lastViking.receiveDamage(firstSaxon.attack()); + + if(lastViking.health <= 0){ + this.vikingArmy.pop(); + } + + return saxonAtkViking; + } + + showStatus(){} +} From b97c892080160314b12c991b7357fe27fe3ef420 Mon Sep 17 00:00:00 2001 From: Victor Hugo Date: Wed, 7 Jan 2026 19:24:46 +0000 Subject: [PATCH 3/3] Solved lab --- src/viking.js | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/viking.js b/src/viking.js index 01a44286b..2518185fd 100755 --- a/src/viking.js +++ b/src/viking.js @@ -62,31 +62,39 @@ class War { this.saxonArmy.push(saxonObj); } - vikingAttack(){ - const lastSaxon = this.saxonArmy[this.saxonArmy.length - 1] - const firstViking = this.vikingArmy[0] - - const vikingAtkSaxon = lastSaxon.receiveDamage(firstViking.attack()); + attackMovement(attackingArr, defendingArr){ + const firstAttacker = attackingArr[0]; + const lastDefender = defendingArr[defendingArr.length - 1]; + + const attackAgainstDefense = lastDefender.receiveDamage(firstAttacker.attack()); - if(lastSaxon.health <= 0){ - this.saxonArmy.pop(); + if(lastDefender.health <= 0){ + defendingArr.pop(); } - - return vikingAtkSaxon; + + return attackAgainstDefense; + } + + vikingAttack(){ + return this.attackMovement(this.vikingArmy, this.saxonArmy); } saxonAttack(){ - const lastViking = this.vikingArmy[this.vikingArmy.length - 1]; - const firstSaxon = this.saxonArmy[0]; + return this.attackMovement(this.saxonArmy, this.vikingArmy); + } - const saxonAtkViking = lastViking.receiveDamage(firstSaxon.attack()); - if(lastViking.health <= 0){ - this.vikingArmy.pop(); + showStatus(){ + if(this.saxonArmy.length === 0){ + return `Vikings have won the war of the century!` } - return saxonAtkViking; - } + if(this.vikingArmy.length === 0){ + return `Saxons have fought for their lives and survived another day...` + } - showStatus(){} + if(this.vikingArmy.length > 0 && this.saxonArmy.length > 0){ + return `Vikings and Saxons are still in the thick of battle.` + } + } }