Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Level Toil and Trouble


can anyone help me by this level?

here is my code:

this.chooseTarget = function(friend) {
    if (friend == "soldier") {
        return this.findByType("witch");
    else {
        return this.findEnemies(); 
loop {
    var friends = this.findFriends();
    for(i=0; i < friends.length; i++) {            
        var friend = friends[i];
        var enemy =  friend.findNearest(this.chooseTarget(friend.type));
        if (enemy) {
            this.command(friend, "attack", enemy);


Try friend.type instead of “friend” in line 2.


the Qode works
but i dont win the level


Should work with that change; what ends up happening?


at the end not all ogres die
I dont have an idea what I can do
please help me


Your guys die before killing them? Do the soldiers go straight for the witches, while the archers shoot the nearest ogres to themselves? Or do the soldiers attack the nearest ogres, too?

Remember you have to make the change GundericusTheMighty suggested.


yes my guys die before
the soldiers attack only the witches and the archers attack the nearest orgres


What are the archers attacking? They should be going after the throwers first.


Depending on what glasses you have equipped for some reason you can’t always see the bottom throwers. Your friends can, so you could replace this.findEnemies() with friend.findEnemies().


thank you very much trotod
now it works :smile: