String Cartography explainer

Hi Grasshoppers,

I’ve got the problem, that in my code it seems to be an error, which I just don’t understand. After I completed each line, I had a look in here and found, that I had the same as a lot of people here. There ist still the error, that the code misses a variable for letter, which I obviously have, haven’t I?

Might you have a look?

Hey there, the issue is in the setup for your for loop:

for (let i = 0; i < letter.length; i++)

When this line of code runs, letter has not yet been declared, so the computer doesn’t know what it is. Change letter to string.

string is the parameter for the function. When the function is called, this could be a value like 'animal' or 'balloon'.

We want to loop through this string, which is why we use the parameter in the for loop like this:

for (let i = 0; i < string.length; i++)

Inside the for loop, letter is declared to give us a quicker and cleaner way to refer to the current letter of the string as the string is being looped through, like this:

let letter = string[i];

On the 1st loop, letter will be string[0], for example, the 1st 'a' in 'animals', or the 'b' in 'balloon'.

On the 2nd loop, letter will be string[1], and so on…

Hope that makes sense! Let me know if you have any questions.
Ben

Hi Ben,

I see. I totally have overseen it. Thanks so much!

1 Like

I have some trouble using “let”, something is missing and I could not find what…