# Don't Touch Them (JavaScript)

**URL:** <https://discourse.codecombat.com/t/dont-touch-them-javascript/25970>\
**Category:** Level Help\
**Created:** [December 9, 2020, 9:17pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970 "2020-12-09T21:17:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdad](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jdad](https://discourse.codecombat.com/u/jdad)\
**Post date:** [December 9, 2020, 9:17pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/1 "2020-12-09T21:17:11Z")

</div>

I’m stuck on the level Don’t Touch Them. I read through another thread but it dod not solve the problem and the thread cut off before someone really helped. Can someone please help me? There are no code errors that pop up and I hit the goals but the level does not end. Here’s the code I used:

function createGenerator(spawnType, x, y, spawnAI) {  
var generator = game.spawnXY(“generator”, x, y);  
generator.spawnType = spawnType;  
generator.spawnAI = spawnAI;  
}

// Scouts are aggressive and munchkins are just walking.  
createGenerator(“scout”, 12, 12, “AttacksNearest”);  
createGenerator(“scout”, 68, 56, “AttacksNearest”);  
createGenerator(“munchkin”, 12, 56, “Scampers”);  
createGenerator(“munchkin”, 68, 12, “Scampers”);

var player = game.spawnPlayerXY(“duelist”, 40, 34);  
player.maxHealth = 1000;  
player.attackDamage = 20;  
player.maxSpeed = 20;

// These are our goals. Notice we save them in variables!  
var spawnMunchkinsGoal = game.addManualGoal(“Let 6 munchkins spawn.”);  
var dontTouchGoal = game.addManualGoal(“Don’t attack munchkins.”);  
var defeatScoutsGoal = game.addManualGoal(“Defeat 6 scouts.”);  
// game properties used to count new and defeated ogres.  
game.spawnedMunchkins = 0;  
game.defeatedScouts = 0;  
game.successGoal = 0;  
ui.track(game, “spawnedMunchkins”);  
ui.track(game, “defeatedScouts”);

function onSpawn(event) {  
game.spawnedMunchkins += 1;  
}

function onDefeat(event) {  
var unit = event.target;  
if (unit.type == “scout”) {  
game.defeatedScouts += 1;  
}  
if (unit.type == “munchkin”) {  
// dontTouchGoal is failed if a munchkin is defeated.  
game.setGoalState(dontTouchGoal, false);  
player.say(“Oops.”);  
}  
}

function checkGoals() {  
// If game.defeatedScouts is greater than 5:  
if (game.defeatedScouts \> 5) {  
// Set defeatScoutsGoal state as successful…  
game.setGoalState(defeatScoutsGoal, true);  
}  
// If game.spawnedMunchkins is greater than 5:  
if (game.spawnMunchkins \> 5) {  
// Set spawnMunchkinsGoal state as successful…  
game.setGoalState(spawnMunchkinsGoal, True);  
}  
// If both other goals are completed.  
if (spawnMunchkinsGoal.success) {  
if (defeatScoutsGoal.success) {  
// Set dontTouchGoal state as successful…  
game.setGoalState(dontTouchGoal, true);  
}  
}  
}

game.setActionFor(“munchkin”, “spawn”, onSpawn);  
game.setActionFor(“munchkin”, “defeat”, onDefeat);  
game.setActionFor(“scout”, “defeat”, onDefeat);

while (true) {  
checkGoals();  
}

---

<div class="post-metadata">

**Author:** ![ineedhelpwithcoding](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ineedhelpwithcoding/32/30168_2.png) [@ineedhelpwithcoding](https://discourse.codecombat.com/u/ineedhelpwithcoding)\
**Post date:** [December 10, 2020, 5:55am UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/2 "2020-12-10T05:55:11Z")

</div>

please format your code properly using this

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/1/1/11a11106a9c863b9b0dd3f46ffb90cb75562676e.png)

---

<div class="post-metadata">

**Author:** ![jdad](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jdad](https://discourse.codecombat.com/u/jdad)\
**Post date:** [December 10, 2020, 6:35pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/3 "2020-12-10T18:35:30Z")

</div>

I did format it properly but when I pasted it in this chat the formats were removed. See screenshot:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/9/8/986f4b6778151b49a53668e07be11151a58a755b.png)

---

<div class="post-metadata">

**Author:** ![jdad](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jdad](https://discourse.codecombat.com/u/jdad)\
**Post date:** [December 10, 2020, 6:42pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/4 "2020-12-10T18:42:18Z")

</div>

> [@jdad](#):
>
> perly but when I pasted it in this chat the form

function createGenerator(spawnType, x, y, spawnAI) {  
var generator = game.spawnXY(“generator”, x, y);  
generator.spawnType = spawnType;  
generator.spawnAI = spawnAI;  
}

// Scouts are aggressive and munchkins are just walking.  
createGenerator(“scout”, 12, 12, “AttacksNearest”);  
createGenerator(“scout”, 68, 56, “AttacksNearest”);  
createGenerator(“munchkin”, 12, 56, “Scampers”);  
createGenerator(“munchkin”, 68, 12, “Scampers”);

var player = game.spawnPlayerXY(“duelist”, 40, 34);  
player.maxHealth = 1000;  
player.attackDamage = 20;  
player.maxSpeed = 20;

// These are our goals. Notice we save them in variables!  
var spawnMunchkinsGoal = game.addManualGoal(“Let 6 munchkins spawn.”);  
var dontTouchGoal = game.addManualGoal(“Don’t attack munchkins.”);  
var defeatScoutsGoal = game.addManualGoal(“Defeat 6 scouts.”);  
// game properties used to count new and defeated ogres.  
game.spawnedMunchkins = 0;  
game.defeatedScouts = 0;  
ui.track(game, “spawnedMunchkins”);  
ui.track(game, “defeatedScouts”);

function onSpawn(event) {  
game.spawnedMunchkins += 1;  
}

function onDefeat(event) {  
var unit = event.target;  
if (unit.type == “scout”) {  
game.defeatedScouts += 1;  
}  
if (unit.type == “munchkin”) {  
// dontTouchGoal is failed if a munchkin is defeated.  
game.setGoalState(dontTouchGoal, false);  
player.say(“Oops.”);  
}  
}

function checkGoals() {  
// If game.defeatedScouts is greater than 5:  
if (game.defeatedScouts \> 5) {  
// Set defeatScoutsGoal state as successful…  
game.setGoalState(defeatScoutsGoal, true);  
}  
// If game.spawnedMunchkins is greater than 5:  
if (game.spawnMunchkins \> 5) {  
// Set spawnMunchkinsGoal state as successful…  
game.setGoalState(spawnMunchkinsGoal, True);  
}  
// If both other goals are completed.  
if (spawnMunchkinsGoal.success) {  
if (defeatScoutsGoal.success) {  
// Set dontTouchGoal state as successful…  
game.setGoalState(dontTouchGoal, true);  
}  
}  
}

game.setActionFor(“munchkin”, “spawn”, onSpawn);  
game.setActionFor(“munchkin”, “defeat”, onDefeat);  
game.setActionFor(“scout”, “defeat”, onDefeat);

while (true) {  
checkGoals();  
}`Preformatted text`

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [December 10, 2020, 6:45pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/5 "2020-12-10T18:45:27Z")

</div>

Click on this button:  
 ![2020-12-10_13-46-03](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/f/f/ffafaaee2442df8d8545f60696ec7421f5dd42bd.png)  
Then type your code in here:  
 ![2020-12-10_13-46-46](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/c/8/c833921eef3d14994be3c58f683509638006726b.png)

So this code:

while True:  
hero.say(“hi”)

Should be:

```python
while True:
    hero.say("hi")

```

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [December 10, 2020, 10:30pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/8 "2020-12-10T22:30:01Z")

</div>

You are supposed to replace the line “type or paste code here” with your code.

---

<div class="post-metadata">

**Author:** ![jdad](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jdad](https://discourse.codecombat.com/u/jdad)\
**Post date:** [December 10, 2020, 10:32pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/9 "2020-12-10T22:32:06Z")

</div>

> [@jdad](#):
>
> ion createGenerator(spawnType, x, y, spawnAI) {  
> var generator = game.spawnXY(“generator”, x, y);  
> generator.spawnType = spawnType;  
> generator.spawnA

I just did what you said, I used pasye. When I pasted the code it looked proper. Then I posted it and it took away the indentations.

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [December 10, 2020, 10:32pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/10 "2020-12-10T22:32:15Z")

</div>

> [@abc](#):
>
> while True:  
> hero.say(“hi”)
> 
> Should be:
> 
> ```python
> while True:
> hero.say("hi")
> 
> ```

Do you see the difference between these two codes? One is formatted and the other is not.

---

<div class="post-metadata">

**Author:** ![jdad](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jdad](https://discourse.codecombat.com/u/jdad)\
**Post date:** [December 10, 2020, 10:35pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/11 "2020-12-10T22:35:53Z")

</div>

I do see the difference and that is what it looks like when I paste it.

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [December 10, 2020, 10:37pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/12 "2020-12-10T22:37:27Z")

</div>

![Screenshot 2020-12-10 at 5.35.52 PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/d/5/d5771c86c2d91ce8705bc58412715dc1447a5b40.png)

Writing the above like that ends up looking like this:

 ![Screenshot 2020-12-10 at 5.36.06 PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/0/7/0731fc98c8951b75b0d05be9f68bf7d1486c6bbd.png)

---

<div class="post-metadata">

**Author:** ![jdad](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jdad](https://discourse.codecombat.com/u/jdad)\
**Post date:** [December 10, 2020, 10:38pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/13 "2020-12-10T22:38:22Z")

</div>

I see the difference. See my screenshoot:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/f/5/f5cd754cd71c446f3335035c6d522ae33a2324a7.png)

---

<div class="post-metadata">

**Author:** ![jdad](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jdad](https://discourse.codecombat.com/u/jdad)\
**Post date:** [December 10, 2020, 10:41pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/15 "2020-12-10T22:41:02Z")

</div>

```python
// Use manual goals to specify which ogres to defeat.

function createGenerator(spawnType, x, y, spawnAI) {
    var generator = game.spawnXY("generator", x, y);
    generator.spawnType = spawnType;
    generator.spawnAI = spawnAI;
}

// Scouts are aggressive and munchkins are just walking.
createGenerator("scout", 12, 12, "AttacksNearest");
createGenerator("scout", 68, 56, "AttacksNearest");
createGenerator("munchkin", 12, 56, "Scampers");
createGenerator("munchkin", 68, 12, "Scampers");

var player = game.spawnPlayerXY("duelist", 40, 34);
player.maxHealth = 1000;
player.attackDamage = 20;
player.maxSpeed = 20;

// These are our goals. Notice we save them in variables!
var spawnMunchkinsGoal = game.addManualGoal("Let 6 munchkins spawn.");
var dontTouchGoal = game.addManualGoal("Don't attack munchkins.");
var defeatScoutsGoal = game.addManualGoal("Defeat 6 scouts.");
// game properties used to count new and defeated ogres.
game.spawnedMunchkins = 0;
game.defeatedScouts = 0;
ui.track(game, "spawnedMunchkins");
ui.track(game, "defeatedScouts");

function onSpawn(event) {
    game.spawnedMunchkins += 1;
}

function onDefeat(event) {
    var unit = event.target;
    if (unit.type == "scout") {
        game.defeatedScouts += 1;
    }
    if (unit.type == "munchkin") {
        // dontTouchGoal is failed if a munchkin is defeated.
        game.setGoalState(dontTouchGoal, false);
        player.say("Oops.");
    }
}

function checkGoals() {
    // If game.defeatedScouts is greater than 5:
    if (game.defeatedScouts > 5) {
        // Set defeatScoutsGoal state as successful..
        game.setGoalState(defeatScoutsGoal, true);
    }
    // If game.spawnedMunchkins is greater than 5:
    if (game.spawnMunchkins > 5) {
        // Set spawnMunchkinsGoal state as successful..
        game.setGoalState(spawnMunchkinsGoal, True);
    }
    // If both other goals are completed.
    if (spawnMunchkinsGoal.success) {
        if (defeatScoutsGoal.success) {
            // Set dontTouchGoal state as successful..
            game.setGoalState(dontTouchGoal, true);
        }
    }
}

game.setActionFor("munchkin", "spawn", onSpawn);
game.setActionFor("munchkin", "defeat", onDefeat);
game.setActionFor("scout", "defeat", onDefeat);

while (true) {
    checkGoals();
}

```

---

<div class="post-metadata">

**Author:** ![jdad](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jdad](https://discourse.codecombat.com/u/jdad)\
**Post date:** [December 10, 2020, 10:42pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/16 "2020-12-10T22:42:59Z")

</div>

Thank you! I finally was able to post it properly. Can you look at it and help me? I have been stuck here for two days. They do not even have the answers this level online like some of the other levels if you can’t figure it out.

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [December 10, 2020, 10:44pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/17 "2020-12-10T22:44:48Z")

</div>

When you play the level, only click on the scouts. **Do not click on the munchkins.**

---

<div class="post-metadata">

**Author:** ![jdad](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jdad](https://discourse.codecombat.com/u/jdad)\
**Post date:** [December 10, 2020, 10:46pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/18 "2020-12-10T22:46:14Z")

</div>

That’s what I do. I get over 6 scouts on my board but it just keeps going:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/f/d/fdc4363282d233362d97b03cc5a833f4e7094f91.jpeg)

---

<div class="post-metadata">

**Author:** ![jdad](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jdad](https://discourse.codecombat.com/u/jdad)\
**Post date:** [December 10, 2020, 10:48pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/20 "2020-12-10T22:48:05Z")

</div>

> [@abc](#):
>
> on the scouts. **Do not**

The screenshot shows that I killed 7 there.

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [December 10, 2020, 10:54pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/21 "2020-12-10T22:54:52Z")

</div>

I don’t see what is wrong.

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [December 10, 2020, 11:18pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/22 "2020-12-10T23:18:42Z")

</div>

> [@jdad](#):
>
> ```python
> if (game.defeatedScouts > 5) {
> // Set defeatScoutsGoal state as successful..
> game.setGoalState(defeatScoutsGoal, true);
> 
> ```

@jdad, I found it!  
Replace true with True, it needs to be capitalized.

---

<div class="post-metadata">

**Author:** ![jdad](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jdad](https://discourse.codecombat.com/u/jdad)\
**Post date:** [December 10, 2020, 11:25pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/23 "2020-12-10T23:25:39Z")

</div>

I don’t get it. I kill more than 7 scouts. I do not attack the scouts, it says ouch if I do so I know I didn’t. Thank you for trying to help me!

I replaced the True with true and it still will not work

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [December 10, 2020, 11:46pm UTC](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970/24 "2020-12-10T23:46:53Z")

</div>

You are supposed to replace true with True.

[Next page](https://discourse.codecombat.com/t/dont-touch-them-javascript/25970.md?page=2)
