# Desert basin stampede javascript

**URL:** https://discourse.codecombat.com/t/desert-basin-stampede-javascript/22119
**Category:** Level Help
**Created:** [June 9, 2020, 5:14am UTC](https://discourse.codecombat.com/t/desert-basin-stampede-javascript/22119 "2020-06-09T05:14:05Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Ksensei](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ksensei/32/12821_2.png) [@Ksensei](https://discourse.codecombat.com/u/Ksensei)
#### Post date: [June 9, 2020, 5:14am UTC](https://discourse.codecombat.com/t/desert-basin-stampede-javascript/22119/1 "2020-06-09T05:14:05Z")

</div>

hello, in desert “basin stampede” even when code is wrong, once hero stops if you have enough hp the yaks push you to the oasis and you successfully complete. can i have any hints with code please? ^^ tried various things

also - what is “accessing properties” refering to?  
 ![accesing](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/2/20d7511d361149497a3d00371dca3b0d4273fd26.png)  
my code (i edited a bit to not be absolute obvious)

```python
javascript
while (true) {
    var enemy = hero.findNearestEnemy();
    var xPos = hero.pisition + 5;
       var yPos = 17;
    if (enemy) {
        // Adjust y up or down to get away from yaks.
        if (enemy.position > hero.position) {
            // If the Yak is above you, subtract 3 from yPos.
            hero.moveXY(x, y - 3);
        } else if (enemy.position < hero.position-3)
 {
            // If the Yak is below you, add 3 to yPos.
            hero.moveXY(x, y + 3);
        }
    }
    hero.moveXY(x, y);

```

about var yPos-\> shouldnt it be outside the loop, so that the player begins from y=17 but once loop starts it needs to be constantly changing…  
btw-im not sure but I saw some people writing its not allowed to post full code, if so - how should i post it? i cant show only parts of it since i dont know where exactly the problem is…  
sorry for all the noobish questions ^^"

---

<div class="post-metadata">

### Author: ![jka2706](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jka2706/32/13636_2.png) [@jka2706](https://discourse.codecombat.com/u/jka2706)
#### Post date: [June 9, 2020, 7:33am UTC](https://discourse.codecombat.com/t/desert-basin-stampede-javascript/22119/2 "2020-06-09T07:33:05Z")

</div>

Hi Ksensei,

Well done on completing the level - yes sometimes I’ve completed even with ‘wrong’ code; I think just small bugs (or maybe look at it that that’s like real life - sometimes things go right even when they shouldn’t really - and sometimes you have the right code but the wrong armour, or are just unlucky with the starting seed). Sometimes I go back and work through the problems to learn more, and sometimes I just accept it.

moveXY needs 2 numbers in the brackets to work, which is the error that is showing.

I’m not quite sure about the answer to your question about accessing properties, I’ll leave it to someone else to answer.

With the var yPos inside the loop, I think it means that your hero will come back to that y pos on each loop, and can then move +/- 3 from it. If you put the starting y pos outside the loop then the hero would be able to move much further - possibly off the screen. It depends what you want to happpen.

Re code - CoCo asks that answers aren’t posted, so that other people have to work things out rather than just copy and pasting someone else’s; but there seems to be a level of reasonableness about this. If your code sort of works but you have questions about it, then maybe keep it up for a few days while folk look at it to answer your questions, and then edit your post to take it down?

No need to apologise for asking questions - questions are good 😄.

---

<div class="post-metadata">

### Author: ![Ksensei](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ksensei/32/12821_2.png) [@Ksensei](https://discourse.codecombat.com/u/Ksensei)
#### Post date: [June 9, 2020, 10:05am UTC](https://discourse.codecombat.com/t/desert-basin-stampede-javascript/22119/3 "2020-06-09T10:05:50Z")

</div>

thx for reply ^^ i always move forward and back to whatever i can, but i really want to understand why something isnt working…  
i tried various things with

```python
 hero.moveXY(xPos, yPos);

```

(i know its marking it in the screenshot but you see in the code i posted its with parameters)  
although if im not the only one maybe it really is a bug in the spesific level, ill wait for more replies ^^

---

<div class="post-metadata">

### Author: ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)
#### Post date: [June 9, 2020, 2:22pm UTC](https://discourse.codecombat.com/t/desert-basin-stampede-javascript/22119/4 "2020-06-09T14:22:55Z")

</div>

Think of the behavior as more of an exploit, rather than a bug. There are several levels throughout the campaigns where brute force will succeed, even when the code won’t. The goal is to figure out a method to solve the level…preferably with proper coding, but this is not implicitly stated. Therefore, even though you passed (good job btw!), the challenge, should you choose to accept it, is to figure out what’s wrong with your code (which includes asking for help if needed) and fix it.

There is nothing wrong with posting all of your code, if you are needing help. Sometimes this is even required, as the issue could be in one place, but shows up in another. There is also nothing wrong with only posting the problem block of code…it all depends on the particular piece being worked on. As jka mentions, you can always edit your posts if you feel the need…replacing the entire code with just the problem line of code is not a bad idea.

“Accessing Properties”. Properties and attributes…they are members of an ‘object’. Something that defines, or describes, an object. This level gives a very basic look at the ‘.pos’ property. Take this line as an example:

```python
var xPos = hero.pos.x + 5;

```

xPos is the variable being defined. It is defined as hero.pos.x + 5. ‘hero’ is the object, ‘.pos’ is the property and ‘.x’ is the attribute…’.pos’, the property, actually has other attributes, such as ‘.y’ too. In coming levels this will be explored a bit deeper…

---

<div class="post-metadata">

### Author: ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)
#### Post date: [June 9, 2020, 2:31pm UTC](https://discourse.codecombat.com/t/desert-basin-stampede-javascript/22119/5 "2020-06-09T14:31:24Z")

</div>

Now, to the meat of the problem. You define yPos as = 17:

```python
       var yPos = 17;

```

But, you never redefine it…yPos is always going to equal 17. Instead of moving inside your ‘if block’, try simply redefining yPos instead. Your final statement is the only ‘move’ command needed.

---

<div class="post-metadata">

### Author: ![EpicCoder999](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/epiccoder999/32/12768_2.png) [@EpicCoder999](https://discourse.codecombat.com/u/EpicCoder999)
#### Post date: [June 9, 2020, 6:30pm UTC](https://discourse.codecombat.com/t/desert-basin-stampede-javascript/22119/6 "2020-06-09T18:30:15Z")

</div>

All I did is stand there and let the yaks push me to the oasis

---

<div class="post-metadata">

### Author: ![Ksensei](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ksensei/32/12821_2.png) [@Ksensei](https://discourse.codecombat.com/u/Ksensei)
#### Post date: [June 11, 2020, 8:33am UTC](https://discourse.codecombat.com/t/desert-basin-stampede-javascript/22119/7 "2020-06-11T08:33:01Z")

</div>

i started doing the desert from beginning to see what ive been missing cause am starting to get confused on advanced stages and i happenned to solve this one with simply adding

```python
    else {
    hero.moveXY(xPos, yPos);
}

```

at the bottom line before the hero.move!  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/0/0310880735054cbcaf5a5153714dc1ee930d7545.png)  
works perfect now

BUT at submit (at first run it worked) it didnt work and hero stops on spot, for the same code  
i think there IS a bug in this stage, its inconsistent
