Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
Warriorjs level 5 dungeon

I just started https://warriorjs.com/. I'm on level 5 now, I can do this by doing a million if else statements, but I saw people make separate functions, to make it easier to work and read later on.

  • How to create a function (is enemy or it is a captive in front of me)?
  • I created function isCaptive (warrior), but I get an Error: isCaptive is not defined.
class Player {
    /**
     * Plays a warrior turn.
     *
     * @param {Warrior} warrior The warrior.
     */
    playTurn(warrior) {
        // Cool code goes here
        if (this.health > warrior.health()) {
            if (warrior.feel().isEmpty()) {
                warrior.walk();
            } else {
                isCaptive(warrior);
            }
        } else {
            if ((warrior.health() !== warrior.maxHealth()) && warrior.feel().isEmpty()) {
                warrior.rest();
            } else if (warrior.feel().isEmpty()) {
                warrior.walk();
            } else {
                warrior.attack();
            }
        }
        this.health = warrior.health();

    }
    isCaptive(warrior) {
        if (warrior.feel().getUnit().isEnemy()) {
            warrior.attack();
        } else if (warrior.feel().getUnit().isBound()) {
            warrior.rescue();
        }
    }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!