Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Forest Cannon Dancing JS

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.

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

Stick with your corrected, original code. This code is valid, just not quite complete:

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

All that you are missing is the logic needed to determine where the pet needs to move. Something like this:

function onSpawn(event) {
    if pet is at point A {
        then move pet to point B
    }
    otherwise { //pet is already at point B so...
        move pet to point A
    }
}

ok thank you very much

@freshkid006 congragulations on finishing the level remember to mark this as solved

@Jeremy_Yu but I didn’t finish it😐

how, like why???

How what? (20 characters)

u said u did’t solve it

Yes, I did not solve it because its incorrect.

and i dont do javascript

oh how sad, :frowning:

repost your code please…let’s see where you are at now

Right… so if u don’t do Javascript, u won’t know if its correct right?