Second "for" loop/cannot read propert 'length' of undefined


#1


I'm stuck in the second "for loop" the site accepts my code and will move on but it says

" TypeError: Cannot read property 'length' of undefined"
which I know will hold me up in later stages (also I want to know how to do it right!)

My code looks like this...
If someone could point me in the right direction I would super appreciate it!


for (i = 0; i <= text.length; i++) {
if ( text[i] === myName[0]) {for (j = i; j <= (i + myName.length); i++) {
    hits.push(text[j])}
    }
}
var text = "Also a little bit of just nodding but no way to tell if they understand, how to check for Maggie comprehension without a show  \ demonstrate, they do, feedback/modification because that takes a lot of time. Maggie How to assess \ understanding better create a culture Maggi how d we it’s ok to ask questions/voice those concerns,  \ like in classes they nod then stay back after Maggie and ask a bunch of questions because not comfortable asking in class"
var myName = "Maggie"
var hits = [ ]
if (hits.length === 0) {
    console.log("Your name wasn't found!")
}
else {
    console.log(hits);
}


#2

Never mind i got it!


#3

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