i am at level “long range division” and here is my code. There are 2 enemies. This kills only one of my enemies. what am i missing in the code? Please help.
Thank you.
// Destroy the mines!
// Use say to call out the range to the mines.
// Use division to calculate the range.
var enemy = this.findNearestEnemy();
var distanceToEnemy = this.distanceTo(enemy);
// Say first Range: distanceToEnemy divided by 3
this.say("first Range" + distanceToEnemy/3);
this.say("Fire!");
// Say second range: distanceToEnemy divided by 1.5
this.say("second range" + distanceToEnemy/1.5);
this.say("Fire!");
// Say these things for motivation. Really. Trust us.
this.say("Woo hoo!");
this.say("Here we go!");
this.say("Charge!!");
3
loop {
this.attack(enemy);
}
// Now, use a while-true loop to attack the enemies.
// Destroy the mines!
// Use say to call out the range to the mines.
// Use division to calculate the range.
var enemy = hero.findNearestEnemy();
var distanceToEnemy = hero.distanceTo(enemy);
// Say first Range: distanceToEnemy divided by 3
var distance1 = hero.distanceTo(distanceToEnemy / 3);
hero.say(distance1);
// Say second range: distanceToEnemy divided by 1.5
var distance2 = hero.distanceTo(distanceToEnemy / 1.5);
hero.say(distance2);
// Say these things for motivation. Really. Trust us.
hero.say(“Woo hoo!”);
hero.say(“Here we go!”);
hero.say(“Charge!!”);
// Now, use a while-true loop to attack the enemies.
while (true) {
if (enemy)
hero.attack(enemy);
}
@serg
ok. so I still don’t get it. Outside of correctly formatting, what must I type in order to win the level? You can clearly see that I gave it my best guess and it wasn’t good enough. Please help me out!
Also, I don’t really understand the difference between using quotation marks and just using parenthesis. I really am trying to learn the language but sometimes I feel like this game is trying to pidgeonhole me into one ‘answer’, which is how it works, but I really want to get to know the principles behind it: IE: really learn.
Properly formatting it in the forums helps us see what you might’ve done wrong. Using the triple backticks ( ` ) before and after your code displays the code like this:
while(true) {
hero.say("Much easier to read!");
}
Also, the difference between quotation marks ( " ) and parenthesis ( ( and ) ) do two different things within your code.
Parenthesis ( ( and ) ) have different uses inside of your code. They usually contain a set of information to perform/use. They can be used to group commands like so:
var a = (2 + 3) * 4 // This does 2 + 3 first, then multiplies it by 4! Think of PEMDAS from Maths class.
When they are used to call a method, they are called: call operators:
hero.moveLeft(); // No arguments
hero.moveXY(23, 55); // 2 arguments!
Finally they can be used to isolate conditional statements:
if(true) {
}
while(hero.health > 20) {
}
Strings ( " ) are lengths of text that are not used for programming. The words I’m type are all contained within a string in a database somewhere!
"I am a string!" // This is a string.
var stringVariable = "This is also a string" // stringVariable now is a string.
hero.say(stringVariable); // Hero says: "This is also a string."
I hope that helps, and if you format your code according to the FAQ, we might be able to help you debug your code.