Please help me!
I’m at Hit and Freeze level, but I can’t do it. It says “Ran out of time.”
My code:
while (true) {
var enemy = hero.findNearestEnemy();
} function inAttackRange(enemy) {
if (canAttack === true) {
hero.attack(enemy);
}
}
What could be the mistake here?
At a quick glance and if this is all your code, you closed your while loop after the enemy variable so you never run anything else other than finding the enemy.
A few more tips, functions should be built outside of your running code, I always put them at the top. Then you call the function within the code.
function inAttackRange(enemy){
return
}
while(true){
inattackRange(enemy) //example
}
Is canAttack
a function or a variable that you are checking? I don’t see that part specified in this code.
Thanks for your reply.
canAtack is a variable in my code.
I can’t do the part of the code where this instruction is:
Call the inAttackRange (enemy) function with the enemy parameter.
and save the value in the canAttack variable.
If the value stored in canAttack is true, attack!
How can I do this?
I reviewed the level to see how it starts you out.
First part, call the inAttackRange (enemy) function with the enemy parameter and save (assign) the value in the canAttack variable. Combine the 3 parts together all in one line to build the variable with the function value.
- create a variable canAttack
- to save (assign) the value use the = like with the enemy variable
- call the inAttackRange(enemy) function with the enemy variable you used to find your nearest enemy as the parameter.
Second part, If the value stored in canAttack is true,attack! You already had this set up correctly. Since the Function returns the value true or false, the variable will have the value true or false.
if (canAttack === true) {
hero.attack(enemy);
}
Thank for your reply.
I could do the level with help:joy:
Thanks for your reply.
I could do the level with help:joy: