[SOLVED] Forest Cannon Dancing JS

The more i make corrections the more the code dose not work.

// 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("hear", onSpawn);
// Cheer up your pet. Don't remove this:
while (true) {
    hero.say("Run!!!");
    hero.say("Faster!");
}

at first the only problem was that my pet was not happy. Now, the code is all messed up. This was my code before:

// 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!");
}