проблем с 03. Man O War от 06. Programming Fundamentals Mid Exam Retake

Здравейте получавам 90/100 и не мога да разбера къде греша, някой може ли да ми помогне

Благодаря

задача: https://judge.softuni.org/Contests/Practice/Index/1773#2

код: 

function solve(input) {

    pirateShip = input.shift().split(">").map(Number)

    enemyShip = input.shift().split(">").map(Number)

    let maxHealth = Number(input.shift())

    let isDead = false

    let actions = {"Fire": fire, "Defend": defend, "Repair": repair, "Status": stat    

    }

    function fire(index, damage){

        index = Number(index);

        damage = Number(damage);

        if (index >= 0 && index < enemyShip.length) {

          enemyShip[index] = enemyShip[index] - damage;

          if (enemyShip[index] <= 0) {

            isDead = true;

            console.log(`You won! The enemy ship has sunken.`);

            return;

          }

        }

      }

    function defend(startIndex, endIndex, damage){

        startIndex = Number(startIndex);

    endIndex = Number(endIndex);

    damage = Number(damage);

    if ((startIndex >= 0 && startIndex < pirateShip.length) && (endIndex >= startIndex && endIndex <= pirateShip.length - 1)) {

      for (let i = startIndex; i <= endIndex; i++) {

        pirateShip[i] -= damage;

        if (pirateShip[i] <= 0) {

         isDead = true;

          console.log(`You lost! The pirate ship has sunken.`);

          return;

        }

      }

    }

  }

    function repair(index, health){

        index = Number(index);

        health = Number(health);

        if (index >= 0 && index < pirateShip.length) {

          if (pirateShip[index] + health < maxHealth) {

            pirateShip[index] = pirateShip[index] + health;

          } else {

            pirateShip[index] = maxHealth;

          }

     

        }

      }

    function stat(count){

        count = 0

        for (let i = 0; i < pirateShip.length; i++) {

            if(pirateShip[i] < maxHealth * 0.2){

            count++;

          }

        }

        console.log(`${count} sections need repair.`);

     

      }        

    for(let i = 0; i < input.length; i++){

        let [command, index, health, damage] = input[i].split(" ")

        if(input[i] === "Retire") break

        actions[command](index, health, damage)

    }

    if(!isDead){

        console.log(`Pirate ship status: ${pirateShip.reduce((a, v) => a + v, 0)}`)

        console.log(`Warship status: ${enemyShip.reduce((a, v) => a + v, 0)}`)

    }  

}