Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED]Help, Reaping Fire (JavaScript)

my code is working however i cant get past 30 seconds on the actual objectives. if you can see any problems in my code let me know and what i can avoid to do next time. thanks

function chooseStrategy() {
    var enemies = hero.findEnemies();
    // If you can summon a griffin-rider, return "griffin-rider"
    if (hero.costOf("griffin-rider") <={
        return "griffin-rider";
    var fangriders = hero.findByType("fangrider");
    for (var i =0; i < fangriders.length; i++){
        var fangrider = fangriders[i];
        if (fangrider.pos.x < 38) {
            return "____";
        return "collect-coins";
    // Otherwise, return "collect-coins"

function commandAttack() {
    // Command your griffin riders to attack ogres.
    var griffins = hero.findFriends();
    var enemies = hero.findEnemies();
    for (var i =0; i < griffins.length; i++){
        var griffin = griffins[i];
        var enemy = griffin.findNearest(enemies);
        if (enemy) {
            hero.command(griffin, "attack", enemy);
        else {
            hero.command(griffin, "move", {"x":hero.pos.x + 20, "y":griffin.pos.y});

function pickUpCoin() {
    // Collect coins
    var items = hero.findItems();
    var item = hero.findNearest(items);

function heroAttack() {
    // Your hero should attack fang riders that cross the minefield.
    var enemy = hero.findNearest(hero.findByType("fangriders"));
    if (enemy && hero.distanceTo(enemy) < 15){

while(true) {
    var strategy = chooseStrategy();
    // Call a function, depending on what the current strategy is.
    if (strategy == "griffin-rider"){
    else if (strategy == "___"){
    else if (strategy == "collect-coins"){

the ____ = fight back. it wouldnt let me submit without deleting it .

Please explain what this piece of code does. I program in Python so I am not familiar with this line of code.

Also send more information about what errors show up when you run your code. A screenshot would be helpful


all this is saying is that when the fangrider gets closer to the hero by passing x,38 then attack. and unfortunately i’m not getting any errors when i run the code, its just failing.

You can do the same thing much simpler and neater by doing this

var nearestFangrider = hero.findnearest(hero.findByType("fangrider"));
if (nearestFangrider.pos.x < 38){
     resturn "____";

Also you need a faster hero to collect more coins

i have used this method in my original code however it was giving me an error for having it all in one statement. and i have used a faster hero(Arryn) and its still failing