Helpon medical attention java script


#1

I really need help on medical attention. This is my code:

// Ask the healer for help when you’re under one-half health.

while(true) {
    var currentHealth = hero.health;
    var healingThreshold = hero.maxHealth / 2;
    // If your current health is less than the threshold,
    // move to the healing point and say, "heal me".
    // Otherwise, attack. You'll need to fight hard!
    if currentHealth < healingThershold {
        hero.moveXY(65, 46);
        hero.say("heal me");
    } else {
        var enemy = hero.findNearestEnemy();
        hero.attack(enemy);
}

#2

The correct syntax is if (currentHealth < healingThershold) { — you are missing the parentheses in your if statement.


#3

No, it’s because you didn’t spell Healing Threshold properly. Also you didn’t close the else block or check if there was an enemy or not.


#4

One thing at a time. JavaScript does not allow if statements without parentheses. It is a syntax error and should blow up the interpreter before any code gets to run. If CodeCombat does anything else, then it is a bug in the CodeCombat interpreter. This may actually be the case as, if I recall correctly, Aether runs on Acorn’s loose mode. Point is, this is nonstandard syntax as per ECMAScript 2016 Language Specification and will fail to run on any of the real JavaScript engines.

(By the way, @nick @rob is there any reason the AST parser is still running on loose mode?)

And then there’s the typo that you’ve noticed. That is a reference error and throws an error while running the code.

So, it is actually both. :slight_smile:

Nice job at spotting the typo and unclosed block, by the way.


#5

We should be in JS strict mode but with the loose mode parser in JavaScript, so it would throw the error but still try to do something with the code. Note that in Python we are probably switching soon to a new parser that should be much more robust and won’t have the loose parsing mode there any more.