# \[SOLVED\] Gas Attack Help Please

**URL:** https://discourse.codecombat.com/t/solved-gas-attack-help-please/22940
**Category:** Level Help
**Created:** [July 12, 2020, 3:17am UTC](https://discourse.codecombat.com/t/solved-gas-attack-help-please/22940 "2020-07-12T03:17:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Monsty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/monsty/32/20923_2.png) [@Monsty](https://discourse.codecombat.com/u/Monsty)
#### Post date: [July 12, 2020, 3:17am UTC](https://discourse.codecombat.com/t/solved-gas-attack-help-please/22940/1 "2020-07-12T03:17:11Z")

</div>

```python
// Calculate the total health of all the ogres.

function sumHealth(enemies) {
    // Create a variable and set it to 0 to start the sum.
    var totalHealth = 0;
    // Initialize the loop index to 0
    var enemyIndex = 0;
    // While enemyIndex is less than the length of enemies array
    while (enemyIndex < enemies.length) {
       // Add the current enemy's health to totalHealth
       enemies.health += totalHealth;
       // Increment enemyIndex by 1.
       enemyIndex += 1;
    }

    return totalHealth;
}

// Use the cannon to defeat the ogres.
var cannon = hero.findNearest(hero.findFriends());
// The cannon can see through the walls.
var enemies = cannon.findEnemies();
// Calculate the sum of the ogres' health.
var ogreSummaryHealth = sumHealth(enemies); 
hero.say("Use " + ogreSummaryHealth + " grams.");

```

---

<div class="post-metadata">

### Author: ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)
#### Post date: [July 12, 2020, 3:23am UTC](https://discourse.codecombat.com/t/solved-gas-attack-help-please/22940/2 "2020-07-12T03:23:58Z")

</div>

> [@Monsty](#):
>
> `enemies.health += totalHealth;`

Instead of this, you should say that a variabile enemy is enemies[enemyIndex] and then add to totalHealth the enemy’s health.

Andrei

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)
#### Post date: [July 12, 2020, 3:24pm UTC](https://discourse.codecombat.com/t/solved-gas-attack-help-please/22940/3 "2020-07-12T15:24:00Z")

</div>

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