Cant win on signal corpse level

so i played the signal corpse last week,i have
type the code correctly but when i play it i cant win at all, it so hard
to beat the goblin, i always died…there’s mah script (javascript)

loop {
var green = this.findFlag(“green”);
var black = this.findFlag(“black”);
var enemy = this.findNearestEnemy();

if (green) {
    this.pickUpFlag(green);
      this.attack(enemy);
} else if (black) {
    this.pickUpFlag(black);
    this.cleave(enemy);     
    
} else if (enemy && this.distanceTo(enemy) < 10) {
    this.attack(enemy);
    
}
else
this.shield();

}

and really, i cant beat dis level!! i always die and die…i play for 1 weeks but no wins…
when the all goblin is dead and 1 big goblin left, i always out of time when i almost win
can you gimme the strategy how to win dis level?? or the script is wrong? but no errors…

else if ((black) && hero.isReady("cleave")) {

make sure to use the black flag for groups of enemies and the green flag for single big enemies.

walk to the healer if needed, maybe you need better sword/armor?