[SOLVED] Help with Anonymous Bank

So I’m stuck on anonymous bank. Here is my code:

// Find the passwords and get the treasure.

// We intercepted a scout with an encoded message.
var encodedMessage = hero.findNearest(hero.findFriends()).message;
// Here we will store passwords.
var passwordArray = [];
// All real passwords have 5 letters.
var passwordLength = 5;

// Split encodedMessage by using a ";" and save the words in a variable.
var words = encodedMessage.split(";");
// Iterate over all of the words.
for (var word in words) {
    var trimmed = word.trim();
    if (trimmed.length == 5) {
        passwordArray.push(trimmed);
    }
}
    // Trim each word to remove whitespace.
    
    // If the length of the cleaned word is 5:
    
        // Push the cleaned word to passwordArray:
        


// Move to each mark and say the correct password:
var marksPos = [{x: 12, y: 14}, {x: 38, y: 38},
    {x: 42, y: 16}, {x: 54, y: 12}];
for (var i = 0; i < 4; i++) {
    var pos = marksPos[i];
    hero.moveXY(pos.x, pos.y);
    var password = passwordArray[i];
    if (password) {
        hero.say(password);
    } 
    else {
        hero.say("qwerty");
    }
}

I don’t really know what to do.

2 Likes

What problems do you have? The code seems alright…

2 Likes

Try to delete this. Does it work now?

2 Likes

It keeps on saying password is null.

2 Likes

which level is this @twenty-one21, because i might be able to help you?

1 Like

It’s Anonymous Bank (20 chars)

2 Likes

which map? and maybe send a screenshot?

1 Like

So not delete that.
I will be right back now I am looking at my code.

2 Likes

Here’s the direct link: https://codecombat.com/play/level/anonymous-bank?codeLanguage=javascript

2 Likes

ah i haven’t done it… but i could try to help though

1 Like


From the mountain

2 Likes

i’m right behind you! :smile: but how did you get there?

1 Like

Just a suggestion, @twenty-one21 you can just delete those comment lines since you are not using them…this will get rid of the annoying arrows too.

2 Likes

Ok, thanks (20 chars)

2 Likes

Here is the problem.
Put this instead:

var index = 0;
while (index < words.length){
    var word = words[index];
    index ++;

Does it work now?

3 Likes

can you post your new code @twenty-one21?

1 Like

hold on, trying the code

2 Likes
var index = 0;
while (index < words.length) {
    var word = words[index];
    if (trimmed.length == 5) {
        passwordArray.push(trimmed);
    }
    index++;
}

MOD edit: I’ve trimmed down the code to just the problem area. It was very close to a solution. (No harm, no foul to the contributors in this topic!)

2 Likes

After that put this

Does it work now?

3 Likes

Yes, it works! Thanks!

3 Likes