# Gas attack help

**URL:** https://discourse.codecombat.com/t/gas-attack-help/15316
**Category:** Uncategorized
**Created:** [July 24, 2018, 12:27am UTC](https://discourse.codecombat.com/t/gas-attack-help/15316 "2018-07-24T00:27:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)
#### Post date: [July 24, 2018, 12:27am UTC](https://discourse.codecombat.com/t/gas-attack-help/15316/1 "2018-07-24T00:27:37Z")

</div>

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

def sumHealth(enemies):
    # Create a variable and set it to 0 to start the sum.
    totalHealth = 0
    # Initialize the loop index to 0
    enemyIndex = 0
    # While enemyIndex is less than the length of enemies array
    while enemyIndex < len(enemies):
        # Add the current enemy's health to totalHealth
        totalHealth = enemies[index].health
        # Increment enemyIndex by 1.
        index +=1
    return totalHealth

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

```

---

<div class="post-metadata">

### Author: ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)
#### Post date: [July 24, 2018, 1:40am UTC](https://discourse.codecombat.com/t/gas-attack-help/15316/2 "2018-07-24T01:40:31Z")

</div>

1. `# Add the current enemy's health to totalHealth`

It doesn’t say, add the current enemies health to total health. It says enemy’s health (singular possessive, not plural). Yet, you haven’t defined enemy (singular). While iterating through arrays, you’re taking the health of each enemy (one at a time for each iteration) and adding it to totalHealth. What you’ve done is an assignment. You’ve reassigned totalHealth as a variable with a new definition.

1. `# Increment enemyIndex by 1.`  
`index +=1`

Look at this closely. Look at the comments and then look at what you wrote.

---

<div class="post-metadata">

### Author: ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)
#### Post date: [July 24, 2018, 2:00am UTC](https://discourse.codecombat.com/t/gas-attack-help/15316/3 "2018-07-24T02:00:51Z")

</div>

Like this? @MunkeyShynes

```python
currentEnemy = enemies[enemyIndex]

```

---

<div class="post-metadata">

### Author: ![Seojin\_Roy\_Lee](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/seojin_roy_lee/32/23539_2.png) [@Seojin\_Roy\_Lee](https://discourse.codecombat.com/u/Seojin_Roy_Lee)
#### Post date: [July 24, 2018, 2:39am UTC](https://discourse.codecombat.com/t/gas-attack-help/15316/4 "2018-07-24T02:39:24Z")

</div>

not that. There isn’t anything which defines index. read the text right above `index += 1`

---

<div class="post-metadata">

### Author: ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)
#### Post date: [July 24, 2018, 1:28pm UTC](https://discourse.codecombat.com/t/gas-attack-help/15316/5 "2018-07-24T13:28:00Z")

</div>

No, that would be an assignment of enemies[enemyIndex] to the variable currentEnemy. In order to, “_add the current enemy’s health to totalHealth_,” you must define enemy first. I’m sure you’ve done this before in previous levels when iterating through arrays. `enemy = enemies[enemyIndex]`
