# Keeping Time is giving me a headache

**URL:** <https://discourse.codecombat.com/t/keeping-time-is-giving-me-a-headache/35762>\
**Category:** Uncategorized\
**Created:** [June 21, 2023, 9:11pm UTC](https://discourse.codecombat.com/t/keeping-time-is-giving-me-a-headache/35762 "2023-06-21T21:11:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Opinion\_Dogs-Better](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/opinion_dogs-better/32/34448_2.png) [@Opinion\_Dogs-Better](https://discourse.codecombat.com/u/Opinion_Dogs-Better)\
**Post date:** [June 21, 2023, 9:11pm UTC](https://discourse.codecombat.com/t/keeping-time-is-giving-me-a-headache/35762/1 "2023-06-21T21:11:45Z")

</div>

while True:  
# If it’s the first 10 seconds, attack.  
enemy = hero.findNearestEnemy()  
if hero.time \< 10:

```
            if enemy:
              hero.attack(enemy)
    pass
# Else, if it's the first 35 seconds, collect coins.
elif hero.time < 35:
    item = hero.findItems()
    
    pass
# After 35 seconds, attack again!
       else:
     hero.attack(enemy)
    pass

```

---

<div class="post-metadata">

**Author:** ![Opinion\_Dogs-Better](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/opinion_dogs-better/32/34448_2.png) [@Opinion\_Dogs-Better](https://discourse.codecombat.com/u/Opinion_Dogs-Better)\
**Post date:** [June 21, 2023, 9:12pm UTC](https://discourse.codecombat.com/t/keeping-time-is-giving-me-a-headache/35762/2 "2023-06-21T21:12:33Z")

</div>

please help  
ive been working on it for a while now

---

<div class="post-metadata">

**Author:** ![Opinion\_Dogs-Better](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/opinion_dogs-better/32/34448_2.png) [@Opinion\_Dogs-Better](https://discourse.codecombat.com/u/Opinion_Dogs-Better)\
**Post date:** [June 21, 2023, 9:14pm UTC](https://discourse.codecombat.com/t/keeping-time-is-giving-me-a-headache/35762/3 "2023-06-21T21:14:17Z")

</div>

while True:  
# If it’s the first 10 seconds, attack.  
enemy = hero.findNearestEnemy()  
if hero.time \< 10:

```
    if enemy:
        hero.attack(enemy)
    pass
# Else, if it's the first 35 seconds, collect coins.
elif hero.time < 35:
    item = hero.findItems()
    
    pass
# After 35 seconds, attack again!
else:
    hero.attack(enemy)
    pass

```

```python
type or paste code here

```

---

<div class="post-metadata">

**Author:** ![R.Loke](https://avatars.discourse-cdn.com/v4/letter/r/ee59a6/32.png) [@R.Loke](https://discourse.codecombat.com/u/R.Loke)\
**Post date:** [June 22, 2023, 2:01am UTC](https://discourse.codecombat.com/t/keeping-time-is-giving-me-a-headache/35762/4 "2023-06-22T02:01:43Z")

</div>

the top if has something missing. it should be:

```python
if enemy and hero.time<10:

```

---

<div class="post-metadata">

**Author:** ![James\_Pfiffner](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/james_pfiffner/32/22991_2.png) [@James\_Pfiffner](https://discourse.codecombat.com/u/James_Pfiffner)\
**Post date:** [June 22, 2023, 5:46pm UTC](https://discourse.codecombat.com/t/keeping-time-is-giving-me-a-headache/35762/5 "2023-06-22T17:46:17Z")

</div>

Please read [this](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521?u) to format your code
