# Yakstraction - Error in my code?

**URL:** <https://discourse.codecombat.com/t/yakstraction-error-in-my-code/2070>\
**Category:** Adventurer\
**Created:** [December 24, 2014, 9:26pm UTC](https://discourse.codecombat.com/t/yakstraction-error-in-my-code/2070 "2014-12-24T21:26:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjchan](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/tjchan/32/1817_2.png) [@tjchan](https://discourse.codecombat.com/u/tjchan)\
**Post date:** [December 24, 2014, 9:26pm UTC](https://discourse.codecombat.com/t/yakstraction-error-in-my-code/2070/1 "2014-12-24T21:26:23Z")

</div>

Trying to get the hero to just go grab the gold first so I don’t have any lines for actually building decoys yet.

However, she seems to get stuck and not move any further. I’m wondering if I missed anything…if I try this.say(gold); it will respond with an error of “Say what?”

Any ideas what I did wrong in my code?

Thanks!

```
 // Build 4 decoys.
    // Each decoy costs 25 gold.
    // Check this.gold to know when you have enough to build one.
    // Keep a count of decoys you built as you go along.
    // Break out of the loop when you have built 4.
    var decoysBuilt = 0;
    var gold = 0;

loop{
    while (gold < 101) {
        item = this.findNearestItem();
        this.say(item);
        if (item) {
            position = item.pos;
            x = position.x;
            y = position.y;
            this.moveXY(x, y);
            gold = this.gold;
        }
    }
}
this.say("Done building decoys!");
// Go to the banker and report how many decoys you built.
```

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [December 24, 2014, 9:35pm UTC](https://discourse.codecombat.com/t/yakstraction-error-in-my-code/2070/2 "2014-12-24T21:35:20Z")

</div>

Is this Decoy Drill or Yakstraction?

You have a while loop inside your normal loop; I would just use one or the other.

---

<div class="post-metadata">

**Author:** ![tjchan](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/tjchan/32/1817_2.png) [@tjchan](https://discourse.codecombat.com/u/tjchan)\
**Post date:** [December 24, 2014, 9:39pm UTC](https://discourse.codecombat.com/t/yakstraction-error-in-my-code/2070/3 "2014-12-24T21:39:00Z")

</div>

Weird…things started to work and the hero actually goes after the coins now.

This is to save Brandy with decoys so Yakstraction.

---

<div class="post-metadata">

**Author:** ![tjchan](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/tjchan/32/1817_2.png) [@tjchan](https://discourse.codecombat.com/u/tjchan)\
**Post date:** [December 24, 2014, 9:48pm UTC](https://discourse.codecombat.com/t/yakstraction-error-in-my-code/2070/4 "2014-12-24T21:48:52Z")

</div>

Ok! Switched to just a loop by converting the while to an if. Didn’t realize that the yaks will eat you too. LOL.

Passed the level.
