[SOLVED]I need help on In my name JavaScript

I think letter or word is supposed to be in there

2 Likes

But then it gives me this error:

4 Likes

yeah because you did I<
put in word or letter there i think

3 Likes

Screenshot 2021-02-04 at 16.07.09
For both of them this error occurs

4 Likes

dude for your loop put something like this

for(var i=0; i<word; i++)
1 Like

I fixed it already before that, but There are so many ERRORS AAAAAHHHH. its okay. on line 28 I have a moveXY problem, even tho it wa already there when the level generated.

hero.moveXY(16 + chestIndex * 8, 36);

4 Likes

ok I now need to think :grin:

2 Likes

This was just an example from Deadpool198 not the actual code!

3 Likes

oooh. okay, give me a second to fix that up

4 Likes

@JoPro_8000 in your for loop it should be
i<word.length;
change your letter from letter= letterIndex[i]
to something like var currentIndex= letterIndex[i]
then in your if loop you should do
instead of word[i++]==letter
it should be this

if(currentIndex==letter){
return i
}
1 Like

What is your current code?

2 Likes

Sorry guys I was offline for a while, but I fixed what @Falcons118 told me to do and here is my code now:

// You must to find the treasure.

// This function should return the index of a letter:
function letterIndex(word, letter) {
    // Step through each letter as an index of the word.
    for(var i=0; i<word.length; 1){
        // Store a character from the word with the current index.
        var currentIndex= letterIndex[i];
        // If it is the required letter:
        if (currentIndex==letter){
            return i
        }
            // Then return the current index (number).
            return index;
        
    
    
    // If nothing, return a default value
        return -1;
    }   
}

var ogreLetter = "z";
var shaman = hero.findByType("thoktar")[0];

// Find the index and use it for finding the treasure.
var chestIndex = letterIndex(shaman.id, ogreLetter);
hero.moveXY(16 + chestIndex * 8, 36);
3 Likes

@JoPro_8000 are you still here?

Why are there 2 returns?

Change letter to orgeLetter

1 Like

no dont change that to ogreLetter

Oh sorry, I have not done this level yet.

1 Like

@JoPro_8000 get rid of this

Move this in between the two { }

its ok I appreciate you trying to help :grin:

Hi, im still there :slight_smile:

2 Likes

so did you try what I said?