5. Your second "for" loop

  1. Your second "for" loop
    It is telling me I have a syntax error. Help is appreciated!

var text = "Annika, Annika, Annika";
for(var i = 0; i < text.length; i++)
        if (text[i]==='A'){
            for(a=i; j< (a + myName.length; a++)){}
            hits.push (text[j]);
var myName = "Annika";
var hits = []


This should be

for(a=i; a<(a+myName.length; a++)//rest of code

Since you used the variable a, you have to use it througout the code.

Additionally, this code:

This code should be inside the for loop (inside the curly brackets), because without it the for loop wouldn't do anything!
In the for loop, the code inside the curly brackets is what the loop executes, so without anything between the brackets, the for loop wouldn't do anything.

Also, please replace the j with an a since you used a as the variable.

This code should be BEFORE the for loop. Javascript executes code in order of when they are written.

Hope this helped!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.