Is this Javascript? And is this the exact piece of code.
no (20 characters is annoying)
How do we know their id?
So in this level, use
enemy=hero.findNearestEnemy()
to find the enemy.
Then to find their id, just do:
id=enemy.id.
while True:
friend = hero.findNearestFriend()
if friend:
hero.say("To battle, " + friend.id + "!")
# Now find the nearest enemy and tell them to go away.
hero.findNearestEnemy()
if enemy:
enemy = hero.findNearestEnemy()
# What do I put here on this line?
What do I put on that line
And the ogres names are peon.
Put the enemy = hero.findNearestEnemy()
OUT of the if enemy:
. You are defining the enemy after stating it. The computer will not know what “enemy” is until you define it. That’s why if enemy: enemy = hero.findNearestEnemy()
will not work.
Please help. I don’t know what I’m doing wrong.
// Peasants and peons are gathering in the forest.
// Command the peasants to battle and the peons to go away!
while(true) {
var friend = hero.findNearestFriend();
if(friend) {
hero.say("To battle, " + friend.id + “!”);
}
// Now find the nearest enemy and tell them to go away.
var enemy = hero.findNearestEnemy;
if(enemy) {
hero.say(“Go away ,” + enemy.id);
}
}
I’m using javascript BTW.
They keep saying, “Go away undefined,” but it doesn’t show any errors in my code.It Just says at the end that I didn’t complete the objective
I also used indents, but was lazy and copy + pasted it
Welcome to the CodeCombat discourse.
What are you missing here?
In future please do format it, it wasn’t needed this time, but it really doesn’t take very long to do. You an read this topic for instructions on how to format: How to Post Your Code With Radiant, Harmonious Formatting.
Thanks
Danny
i need help with this code!!! can someone help me
hello? is anyone there to hlep mme
if you need help please post your code.
while True:
friend = hero.findNearestFriend()
if friend:
hero.say("To battle, " + friend.id + “!”)
# Now find the nearest enemy and tell them to go away.
enemy = hero.findNearestEnemy()
hero.say(“go away”)
what did i do wrong with it
you need to format your code.
put the quote beside to battle
ok i need help again with this code
Look at your "To battle,"+ friend.id + "!"
part. Do the same thing again except with enemy.id instead of friend.id.