# Timber Turncoat - Help - Javascript

**URL:** <https://discourse.codecombat.com/t/timber-turncoat-help-javascript/32408>\
**Category:** Level Help\
**Created:** [March 18, 2022, 9:53pm UTC](https://discourse.codecombat.com/t/timber-turncoat-help-javascript/32408 "2022-03-18T21:53:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![k2adir](https://avatars.discourse-cdn.com/v4/letter/k/9dc877/32.png) [@k2adir](https://discourse.codecombat.com/u/k2adir)\
**Post date:** [March 18, 2022, 9:53pm UTC](https://discourse.codecombat.com/t/timber-turncoat-help-javascript/32408/1 "2022-03-18T21:53:47Z")

</div>

My code works but soldiers aren’t strong enough

```python
function collect() {
    let item = hero.findNearestItem();
    let coin = item.pos;
    if (hero.gold < 25 && item.value > 2) {
        hero.moveXY(coin.x, coin.y);
         
    }
    else if (hero.gold < 25 && item.value > 1) {
        hero.moveXY(coin.x, coin.y);
    }
    else{
        
        hero.moveXY(coin.x, coin.y);
    }
        
    if (hero.gold > 40) {
        hero.summon("soldier");
                hero.summon("soldier");

      
    }
}
function command() {
    let friends = hero.findFriends();
    let enemy = hero.findNearestEnemy();
    for (let i = 0; i < friends.length; i++) {
        let friend = friends[i];
        if (friend.type == "soldier" && enemy) {
            hero.command(friend, "attack", enemy);
        } else if (friend.type == "soldier" && !enemy) {
            hero.command(friend, "move", {
                "x": 85,
                "y": 45
            });
            continue;
            
        } if (friend.type == "soldier" && friend.health < 100) {
            hero.command(friend, "move", {
                "x": 17,
                "y": 46
            });
        }
    }
}
while (true) {
    collect();
    command();
}

```

---

<div class="post-metadata">

**Author:** ![k2adir](https://avatars.discourse-cdn.com/v4/letter/k/9dc877/32.png) [@k2adir](https://discourse.codecombat.com/u/k2adir)\
**Post date:** [March 18, 2022, 9:55pm UTC](https://discourse.codecombat.com/t/timber-turncoat-help-javascript/32408/2 "2022-03-18T21:55:50Z")

</div>

edit:  
it worked after restarting the browser…

my original code had only

```python
if (hero.gold < 25 ) {
        hero.moveXY(coin.x, coin.y);

```

without other the other ones that you will see on the first post (like value \>1 etc);

but after restarting the browser, they all work

---

<div class="post-metadata">

**Author:** ![cheddarcheese](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cheddarcheese/32/22417_2.png) [@cheddarcheese](https://discourse.codecombat.com/u/cheddarcheese)\
**Post date:** [March 18, 2022, 11:17pm UTC](https://discourse.codecombat.com/t/timber-turncoat-help-javascript/32408/3 "2022-03-18T23:17:30Z")

</div>

Welcome to the discourse @k2adir1! I hope you enjoy your time here.

if you are finished with the level please click the checkbox next to one of the replies on this topic to close it thanks.

---

<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:** [March 19, 2022, 11:18am UTC](https://discourse.codecombat.com/t/timber-turncoat-help-javascript/32408/4 "2022-03-19T11:18:12Z")

</div>

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