[SOLVED]I need help on In my name JavaScript

I can’t seem to fix this error:

Here is my code
// 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 i++ in range 0, (length (word), 1){
        // Store a character from the word with the current index.
        var letter= letterIndex[]
        // If it is the required letter:
        if (word [i++] == letter){
            // 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);


Can you give a link to the level Jonathan?

Sure thing, give me a second

@Monsty ? Are you there?

Hey is anyone able to help me? Ive been stuck on this for a while…

@Monsty ? @anon62741001 ?

Yes I am here I am looking over it

Thank you @anon62741001

@abc? you liked my post, can you help me?

I don’t know much Javascript, but doesn’t JS require parenthesis in while statements, if statements, and for statements?

I still get the same error

The main problem is your for loop. What you’ve got above is not how you do it unfortunately.
For loops in javascript take the following format:

for (var i = 0; i < maxNumber; i++) {

Notice the three sections separated by semi colons ( ; ).
Section one declares the variable i as 0.
Section two declares the boolean statement (true of false) which must be true for the loop to run. Meaning, i must be less than a certain maxNumber for it to run. You can use array.length, which contains the number of items in a certain array (like word).
The rest is also wrong, but I’ll let you try and fix that bit first, now that the for loop should work.
Danny

The for loop works now, but I get the error 'expected an Identifier on line 8, but saw ‘]’ ’ on line 8

@JoPro_8000 put the i from the for loop into the brackets
like this

        var letter= letterIndex[i]

add the i onto the brackets

Try putting this under an else statement.

Thanks guys, but now I get the error letter is already defined on line 8:

// 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 < maxNumber; i++) {
        // Store a character from the word with the current index.
        var letter = letterIndex[i];
        // If it is the required letter:
        if (word [i++] == letter){
            // Then return the current index (number).
            return index
        }
    
    
    // If nothing, return a default value
        else{
            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);

yeah delete the var from the var letter= letterIndex[i]

Thanks, I fixed most of the bugs, but in line 6 it says maxNumber not defined

I dont think you are supposed to use max number…