# \[SOLVED\] I need help with Shine Getter, Javascript

**URL:** <https://discourse.codecombat.com/t/solved-i-need-help-with-shine-getter-javascript/15647>\
**Category:** Uncategorized\
**Created:** [August 17, 2018, 1:07pm UTC](https://discourse.codecombat.com/t/solved-i-need-help-with-shine-getter-javascript/15647 "2018-08-17T13:07:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrendGroen](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@BrendGroen](https://discourse.codecombat.com/u/BrendGroen)\
**Post date:** [August 17, 2018, 1:07pm UTC](https://discourse.codecombat.com/t/solved-i-need-help-with-shine-getter-javascript/15647/1 "2018-08-17T13:07:59Z")

</div>

Here is my code:

```python
// To grab the most gold quickly, just go after gold coins.

while(true) {
    var coins = hero.findItems();
    var coinIndex = 0;

    // Wrap this into a loop that iterates over all coins.
    while (coinIndex < coins.length) {
    var coin = coins[coinIndex];
    coinIndex = coinIndex + 1
    // Gold coins are worth 3.
    if (coin.value == 3) {
        // Only pick up gold coins.
        hero.moveXY(goldcoin.pos.x, goldcoin.pos.y);
        
    }  
    }
}

```

When I click on run my hero won’t do anything 😕

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [August 17, 2018, 1:30pm UTC](https://discourse.codecombat.com/t/solved-i-need-help-with-shine-getter-javascript/15647/2 "2018-08-17T13:30:10Z")

</div>

What is goldcoin? Why do you increment the index in the start and not in the end of the loop?

---

<div class="post-metadata">

**Author:** ![BrendGroen](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@BrendGroen](https://discourse.codecombat.com/u/BrendGroen)\
**Post date:** [August 17, 2018, 1:35pm UTC](https://discourse.codecombat.com/t/solved-i-need-help-with-shine-getter-javascript/15647/3 "2018-08-17T13:35:55Z")

</div>

I fixed the goldcoin, this is my code now

```python
// To grab the most gold quickly, just go after gold coins.

while(true) {
    var coins = hero.findItems();
    var coinIndex = 0;

    // Wrap this into a loop that iterates over all coins.
    while (coinIndex < coins.length) {
    var coin = coins[coinIndex];
    // Gold coins are worth 3.
    if (coin.value == 3) {
        // Only pick up gold coins.
        hero.moveXY(coin.pos.x, coin.pos.y);
    }
    }
}

```

---

<div class="post-metadata">

**Author:** ![BrendGroen](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@BrendGroen](https://discourse.codecombat.com/u/BrendGroen)\
**Post date:** [August 17, 2018, 1:36pm UTC](https://discourse.codecombat.com/t/solved-i-need-help-with-shine-getter-javascript/15647/4 "2018-08-17T13:36:35Z")

</div>

my hero will just keep standing still and ive no idea why that is

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [August 17, 2018, 1:43pm UTC](https://discourse.codecombat.com/t/solved-i-need-help-with-shine-getter-javascript/15647/5 "2018-08-17T13:43:43Z")

</div>

In the original code you misses semicolon to _coinIndex = coinIndex + 1_ In the correction you totally deleted that row. You need it, but at the end of the loop. You cannot exit a loop without some exit action and in your case  
this is the incrementation.

---

<div class="post-metadata">

**Author:** ![BrendGroen](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@BrendGroen](https://discourse.codecombat.com/u/BrendGroen)\
**Post date:** [August 17, 2018, 1:48pm UTC](https://discourse.codecombat.com/t/solved-i-need-help-with-shine-getter-javascript/15647/7 "2018-08-17T13:48:13Z")

</div>

Oops, that’s better! Thanks a lot for helping me out 😄

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [August 17, 2018, 1:49pm UTC](https://discourse.codecombat.com/t/solved-i-need-help-with-shine-getter-javascript/15647/8 "2018-08-17T13:49:42Z")

</div>

At the end of the _while (coinIndex \< coins.length_ loop, not in the end of _if coin.value_ condition.  
Ok, you have done it yourself!  
Delete your code in the last message, we don’t have to post whole solutions. ( You can keep the thanks 🙂 )
