# Decoy Drill(JS)\[SOLVED\]

**URL:** <https://discourse.codecombat.com/t/decoy-drill-js-solved/26039>\
**Category:** Level Help\
**Created:** [December 12, 2020, 9:47pm UTC](https://discourse.codecombat.com/t/decoy-drill-js-solved/26039 "2020-12-12T21:47:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [December 12, 2020, 9:47pm UTC](https://discourse.codecombat.com/t/decoy-drill-js-solved/26039/1 "2020-12-12T21:47:52Z")

</div>

problem is that my hero just keeps colecting coins and building decys

```python
// We are field testing a new battle unit: the decoy.
// Build 4 decoys, then report the total to Naria.
var decoysBuilt = 0;
while (true) {
    var coin = hero.findNearestItem();
    if (coin) {
        // Collect the coin!
        hero.moveXY(coin.pos.x, coin.pos.y);
    }
    // Each decoy costs 25 gold.
    // If hero.gold is greater than or equal to 25:
    if (hero.gold > 25) {
        hero.buildXY("decoy", 36, 30);
        decoysBuilt + 1;
    }
    // buildXY a "decoy"
    // Add 1 to the decoysBuilt count.
    if (decoysBuilt == 4) {
        // Break out of the loop when you have built 4.
        break;
    }
}
hero.say("Done building decoys!");
hero.moveXY(14, 36);
// Say how many decoys you built.
hero.say(decoysBuilt);

```

---

<div class="post-metadata">

**Author:** ![WaWa\_Yang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wawa_yang/32/17800_2.png) [@WaWa\_Yang](https://discourse.codecombat.com/u/WaWa_Yang)\
**Post date:** [December 12, 2020, 9:56pm UTC](https://discourse.codecombat.com/t/decoy-drill-js-solved/26039/2 "2020-12-12T21:56:01Z")

</div>

> [@Eric\_Tang](#):
>
> ```python
> **greater than or equal to 25** :
> if (hero.gold > 25) {
> 
> ```

is what i found XD (20 chars)

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [December 12, 2020, 9:57pm UTC](https://discourse.codecombat.com/t/decoy-drill-js-solved/26039/3 "2020-12-12T21:57:28Z")

</div>

Nope didn’t work 20 chars

---

<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:** [December 12, 2020, 10:06pm UTC](https://discourse.codecombat.com/t/decoy-drill-js-solved/26039/4 "2020-12-12T22:06:06Z")

</div>

> [@Eric\_Tang](#):
>
> `decoysBuilt + 1`

change that too `decoysBuilt ++ 1`

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [December 12, 2020, 10:07pm UTC](https://discourse.codecombat.com/t/decoy-drill-js-solved/26039/5 "2020-12-12T22:07:46Z")

</div>

Nope that just gave me a error

 ![Screenshot 2020-12-12 at 3.06.57 PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/b/e/be5e95d35c1b5ed8a37f084034415cf759823a27.jpeg)

```python
// We are field testing a new battle unit: the decoy.
// Build 4 decoys, then report the total to Naria.
var decoysBuilt = 0;
while (true) {
    var coin = hero.findNearestItem();
    if (coin) {
        // Collect the coin!
        hero.moveXY(coin.pos.x, coin.pos.y);
    }
    // Each decoy costs 25 gold.
    // If hero.gold is greater than or equal to 25:
    if (hero.gold > 25 || hero.gold == 25) {
        hero.buildXY("decoy", 36, 30);
        decoysBuilt ++ 1;
    }
    // buildXY a "decoy"
    // Add 1 to the decoysBuilt count.
    if (decoysBuilt == 4) {
        // Break out of the loop when you have built 4.
        break;
    }
}
hero.say("Done building decoys!");
hero.moveXY(14, 36);
// Say how many decoys you built.
hero.say(decoysBuilt);

```

---

<div class="post-metadata">

**Author:** ![WaWa\_Yang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wawa_yang/32/17800_2.png) [@WaWa\_Yang](https://discourse.codecombat.com/u/WaWa_Yang)\
**Post date:** [December 12, 2020, 10:09pm UTC](https://discourse.codecombat.com/t/decoy-drill-js-solved/26039/6 "2020-12-12T22:09:46Z")

</div>

saying things takes time and a few seconds is precious

---

<div class="post-metadata">

**Author:** ![WaWa\_Yang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wawa_yang/32/17800_2.png) [@WaWa\_Yang](https://discourse.codecombat.com/u/WaWa_Yang)\
**Post date:** [December 12, 2020, 10:12pm UTC](https://discourse.codecombat.com/t/decoy-drill-js-solved/26039/7 "2020-12-12T22:12:54Z")

</div>

and change

> [@Eric\_Tang](#):
>
> `decoysBuilt ++ 1;`

into

```python
decoysBuilt += 1;

```

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [December 12, 2020, 10:14pm UTC](https://discourse.codecombat.com/t/decoy-drill-js-solved/26039/8 "2020-12-12T22:14:19Z")

</div>

Thank you guys! 😄

---

<div class="post-metadata">

**Author:** ![WaWa\_Yang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wawa_yang/32/17800_2.png) [@WaWa\_Yang](https://discourse.codecombat.com/u/WaWa_Yang)\
**Post date:** [December 12, 2020, 10:15pm UTC](https://discourse.codecombat.com/t/decoy-drill-js-solved/26039/9 "2020-12-12T22:15:00Z")

</div>

Your welcome @Eric_Tang and congrats on beating the level 🥳

---

<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:** [December 13, 2020, 10:15am UTC](https://discourse.codecombat.com/t/decoy-drill-js-solved/26039/10 "2020-12-13T10:15:10Z")

</div>

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