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

[SOLVED] Short-sighted Burl

Hi,

I don’t understand what am I doing wrong with my code but my hero goes to the marks he has to go but he doesn’t collect the coins. What’s wrong with my code?

// Collect coins and run, or else the burl will find you.
// This function allows your hero take an item.
function takeItem(coin) {
    hero.moveXY(item.pos.x, item.pos.y);
}
// Write the function "checkTakeRun" with one parameter.
// If the item exists, use "takeItem" function to take it.
// Go back to the start (green mark), with or without the item.
function checkTakeRun(coin) {
    if (coin) {
        takeItem;
        hero.moveXY(40, 12);
    } else {
        hero.moveXY(40, 12);
    }
}
// Don't change this code.
while (true) {
    var coin = hero.findNearestItem();
    hero.moveXY(16, 56);
    checkTakeRun(coin);
    hero.moveXY(64, 56);
    coin = hero.findNearestItem();
    checkTakeRun(coin);

The problem is with your checkTakeRun function. On line 3 (of the function), you have ‘takeItem;’. This is meant to be calling the other function…except, the other function is expecting to be passed an object.

Also, you want the hero to move back to the starting X no matter what. Instead of including it in the if statement, move it to the outside, making it the final statement of the function.

Also, you are missing your final closing bracket ‘}’…at least it’s not showing above.

1 Like

@Nick_Combat13

//change this like mentioned above:
 if (coin) {
        takeItem(???); //what are we checking, hint look above

while (true) {
    hero.moveXY(???); // position1
    var coin = hero.findNearestItem();
    checkTakeRun(coin);
    
    hero.moveXY(???); // position2
    coin = hero.findNearestItem(); // updates coin variable to check nearest item.
    checkTakeRun(coin);
}
function argumentVar(parameter1, parameter2, parameter3) { // these are call parameters and can be named anything

  console.log(arguments.length); // Logs the number of arguments passed which is 3

}

argumentVar(1,2,3); // These are called arguments what is in the parenthesis when we call a function

Thanks a lot guys! It worked.

I’m not sure how but it did!

1 Like

Try to break each step down when you run the code to understand better it will help you a lot