Your Second Loop. Help


#1

text = "Hello"
hits = []

for ( i = 0; i < text.length; i++){
    console.log(i)
}
    if (i === text[0]);{
        console.log(i)
        for (j = i; j < i + text.length; j++){
            hits.push(text[j])
        console.log(hits)
        }
    }

Oops, try again. Careful: your second 'for' loop should stop when it reaches its current point in the string + myName.length.

https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661#


#2

uhm.. the moment you do this:

i + text.length

it will go to the end of the text, you should go to the end of your name, try using myName


#3

text = "Hello"
myName = "Alex"
hits = []

for ( i = 0; i < text.length; i++){
    console.log(i)
     if (text[i] === "A");{
        console.log(i)
        for (j = i; j < i + myName.length; j++){
            hits.push(text[j])
        }
    }
}
console.log(hits)

is this correct? I changed the brackets from the first loop to the end. I completed the exercises and got a weird answer


#4

your text variable should also contain your name, since that is what you are trying to find

i see one problem:

if (text[i] === "A");{

the semi-colon you have in this line, prevents the if clause from working properly


#5

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