Help us, Help you. (read the FAQ and allow your code to display properly (use the triple backtick))
What I can tell from what you have there is that there are more open curly braces than close… 5 { but only 3 } other than that it looks good as far as I can tell. I’ll have to go play the level to be sure. – Yup, works for me with the +2 }'s. My hero cleaves the first group, whacks the second, and cleaves the third. (I copied and pasted what is above (so no pretty formatting) and just added the two '}'s to the end.)
First of all Beaute : use proper indentation to provide code for us to help you. See FAQ Section 1 paragraph 2. On the post editor, you can use the </> button also in order to change the code you posted into (the same but more readable).
The main problem to your code is that you don’t have a standard way to write statement. It’s important for readability, but also it helps A LOT to find errors in your code if it has a proper indentation and braces.
A standard pattern to write if statement is the following :
Please, consider reading the box above aloud like this : if space parenthesis space condition1 space closedparenthesis space openbrace newline tab statement1 space semicolon newline tab statement2 space semicolon etc… And try to apply this exact pattern to your code. This is important in debugging a bugged code.
Specific issues other than formating :
1)
if (this.isReady("cleave"));
There is a ; instead of a {
end;
isn’t JS. Replace with }
The else part refers to the wrong if. You want to attack if cleave isn’t ready, not if distance >=5.
Hello, Pevensie, and welcome. Please format your code as per the FAQ.
Unfortunately, it is impossible to conduct a full examination of your code unless it is formatted properly, but you do not appear to attack an enemy unless the distance is greater than 5.
So I also faced this issue multiple times with some of my coding (I have to finish all the levels for a college course, seems easy, right? Not quite!
What I always seem to be seems to be what your’e doing as well, and I’m posting this for future users as well.
After you finish your “if” variable, DON’T close the loop (I’ve done this on 2 levels and had to beat my head against the wall to see the error).
There should only be ONE bracket closing your “if” variable, so it leaves the “else” variable open to continue the loop.
//Made by sanlega, i’ve made it with Java
while(true) {
var enemy = hero.findNearestEnemy();
if (enemy) {
var distance = hero.distanceTo(enemy);
var ready = hero.isReady(“cleave”);
if (distance < 5) {
if (ready) {
hero.cleave(enemy);
}
else {
hero.attack(enemy);
}
}
}
}
Please format your code, you can highlight it and press the “< / >” button in the comment section. Or add two backticks before and after your code. It helps a lot