# Help with solution for "long range division"

**URL:** <https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133>\
**Category:** Uncategorized\
**Created:** [March 30, 2016, 1:22am UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133 "2016-03-30T01:22:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reshmi\_Naveen](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@Reshmi\_Naveen](https://discourse.codecombat.com/u/Reshmi_Naveen)\
**Post date:** [March 30, 2016, 1:22am UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133/1 "2016-03-30T01:22:41Z")

</div>

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.

```python
// 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.

```

---

<div class="post-metadata">

**Author:** ![Serg](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/serg/32/3260_2.png) [@Serg](https://discourse.codecombat.com/u/Serg)\
**Post date:** [March 30, 2016, 4:10pm UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133/2 "2016-03-30T16:10:19Z")

</div>

Look at the loop at the bottom (with a 3 above it? You should remove that, too)

You are attacking the ‘enemy’ that was found at the top of your codeblock, but never trying to find the second enemy.

---

<div class="post-metadata">

**Author:** ![Reshmi\_Naveen](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@Reshmi\_Naveen](https://discourse.codecombat.com/u/Reshmi_Naveen)\
**Post date:** [March 30, 2016, 5:26pm UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133/3 "2016-03-30T17:26:12Z")

</div>

Thank you. will try this out.

---

<div class="post-metadata">

**Author:** ![Reshmi\_Naveen](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@Reshmi\_Naveen](https://discourse.codecombat.com/u/Reshmi_Naveen)\
**Post date:** [March 30, 2016, 5:32pm UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133/4 "2016-03-30T17:32:04Z")

</div>

Its working now. thank you.

---

<div class="post-metadata">

**Author:** ![Ace\_H](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Ace\_H](https://discourse.codecombat.com/u/Ace_H)\
**Post date:** [May 17, 2016, 9:52pm UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133/5 "2016-05-17T21:52:33Z")

</div>

// 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 stuck on this one. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![Serg](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/serg/32/3260_2.png) [@Serg](https://discourse.codecombat.com/u/Serg)\
**Post date:** [May 17, 2016, 11:44pm UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133/6 "2016-05-17T23:44:30Z")

</div>

Please format your code properly. Put your code between two sets of three backticks ( ` ) so it makes it easier to read.

---

<div class="post-metadata">

**Author:** ![Ace\_H](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Ace\_H](https://discourse.codecombat.com/u/Ace_H)\
**Post date:** [May 18, 2016, 12:26am UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133/7 "2016-05-18T00:26:54Z")

</div>

@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.

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![Serg](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/serg/32/3260_2.png) [@Serg](https://discourse.codecombat.com/u/Serg)\
**Post date:** [May 18, 2016, 4:46pm UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133/8 "2016-05-18T16:46:22Z")

</div>

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:

```python
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:

```python
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:

```python
hero.moveLeft(); // No arguments
hero.moveXY(23, 55); // 2 arguments!

```

Finally they can be used to isolate conditional statements:

```python
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!

```python
"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.

---

<div class="post-metadata">

**Author:** ![Devin\_Chopra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/devin_chopra/32/4055_2.png) [@Devin\_Chopra](https://discourse.codecombat.com/u/Devin_Chopra)\
**Post date:** [July 13, 2016, 12:24pm UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133/9 "2016-07-13T12:24:22Z")

</div>

I faced this situation - the hero would blow up the mines, but would only attack a single enemy instead of the two present.

So I tried using advanced eye glasses to put the enemies in array

 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/5/53dd98659b0a0413668971a35027509bf5093748.jpg)

That showed the status as ‘Success’, but with an error - so I tried something else, which worked : -

[redacted, please don’t post solutions]

---

<div class="post-metadata">

**Author:** ![BlackRabbit](https://avatars.discourse-cdn.com/v4/letter/b/f14d63/32.png) [@BlackRabbit](https://discourse.codecombat.com/u/BlackRabbit)\
**Post date:** [February 14, 2017, 10:00pm UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133/10 "2017-02-14T22:00:58Z")

</div>

This is what I put and my hero still only attacks one enemy at the end, could someone read and please advise? Thanks in advance.

# Destroy the mines!

# Use say to call out the range to the mines.

# Use division to calculate the range.

enemy = hero.findNearestEnemy()

distanceToEnemy = hero.distanceTo(enemy)

distanceone = distanceToEnemy / 3  
distancetwo = distanceToEnemy / 1.5

# Say first Range: distanceToEnemy divided by 3

hero.say(distanceone)

# Say second range: distanceToEnemy divided by 1.5

hero.say(distancetwo)

# Say these things for motivation. Really. Trust us.

hero.say(“Woo hoo!”)  
hero.say(“Here we go!”)  
hero.say(“Charge!!”)  
hero.say(“Get em”)

# Now, use a while-true loop to attack the enemies.

while True:  
hero.findNearestEnemy()  
if enemy:  
hero.attack(enemy)

---

<div class="post-metadata">

**Author:** ![BlackRabbit](https://avatars.discourse-cdn.com/v4/letter/b/f14d63/32.png) [@BlackRabbit](https://discourse.codecombat.com/u/BlackRabbit)\
**Post date:** [February 14, 2017, 10:09pm UTC](https://discourse.codecombat.com/t/help-with-solution-for-long-range-division/7133/11 "2017-02-14T22:09:37Z")

</div>

shoot i just realised copy and pasting has not included my indents. I have put them in but re-reading this just made me realise I should have put

while True:  
enemy = hero.findNearestEnemy()  
if enemy:  
hero.attack enemy

I couldn’t see how to edit my question so I have shown what I would have changed here. AND NOW IT WORKS…YAAAYYY Thanks Me. 😄
