[SOLVED] Forest Cannon Dancing JS

The program is saying the only thing I haven’t done is cheer up my pet which I have no idea how to do. What should I do now?

// Your pet should run back and forth on the X marks.
// The hero should cheer the whole time!

// Write the event function onSpawn for the pet.
// This function should make the wolf run back and forth:
// First, run to the right mark, then the left one:
while(true) {
    pet.moveXY(48,8);
    pet.moveXY(12,8);

}
// Cheer up your pet. Don't remove this:
while (true) {
    hero.say("Run!!!");
    hero.say("Faster!");
}

Instead of while true you should put a function called onSpawn and you should put at the beginning of the code this:

pet.on("spawn", onSpawn)

This part is in the function onSpawn.

it says on spawn is not definned

Could you show me your code?

// Your pet should run back and forth on the X marks.
// The hero should cheer the whole time!
function onSpawn();
    
// Write the event function onSpawn for the pet.
// This function should make the wolf run back and forth:
// First, run to the right mark, then the left one:
  pet.on ("spawn", onSpawn);
    pet.moveXY(48,8);
    pet.moveXY(12,8);

// Cheer up your pet. Don't remove this:
while (true) {
    hero.say("Run!!!");
    hero.say("Faster!");

}


I am positive I just messed it up.

This should be after the function.

Here put instead of ;

{

and after

Put

}

idk about dis (20 CHARS DIFHDIHLGHSI@&(@&$)

I think I just did that? I have no idea.

You should make the function onSpawn

here’s my new code:

// Your pet should run back and forth on the X marks.
// The hero should cheer the whole time!

// Write the event function onSpawn for the pet.
// This function should make the wolf run back and forth:
// First, run to the right mark, then the left one:
while(true) {
    pet.moveXY(48, 8);
    pet.moveXY(12,8);
}

pet.on("spawn", onSpawn);
// Cheer up your pet. Don't remove this:
while (true) {
    hero.say("Run!!!");
    hero.say("Faster!");
}

Here put

function onSpawn(event)

I did that and now it says I ran out of time😐

What is your new code?

// Your pet should run back and forth on the X marks.
// The hero should cheer the whole time!

// Write the event function onSpawn for the pet.
// This function should make the wolf run back and forth:
// First, run to the right mark, then the left one:
function onSpawn(event) {
    pet.moveXY(48, 8);
    pet.moveXY(12,8);
}
onSpawn();
pet.on("spawn", onSpawn);
// Cheer up your pet. Don't remove this:
while (true) {
    hero.say("Run!!!");
    hero.say("Faster!");
}

I think you should remove this line.

now it says I am out of time again.

What is your code again?

// Your pet should run back and forth on the X marks.
// The hero should cheer the whole time!

// Write the event function onSpawn for the pet.
// This function should make the wolf run back and forth:
// First, run to the right mark, then the left one:
function onSpawn(event) {
    pet.moveXY(48, 8);
    pet.moveXY(12,8);
}

pet.on("spawn", onSpawn);
// Cheer up your pet. Don't remove this:
while (true) {
    hero.say("Run!!!");
    hero.say("Faster!");
}

It looks mostly good now, except your pet is trying to listen for your encouragement. In the ‘pet.on’ statement, you want “hear” instead of “spawn”.

Also, in the onSpawn function, you need to add logic to determine which X the pet is currently at; once this is determined, have him run to the other X. A simple if/else if statement should work fine.