Browser crashing when executing double for loop for Search Text


#1


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


Browser crashes.


var text = "dbgk gfdd Naz egribdb awfesgd \
kjm Naz wweongnir efgg Naz";

var myName = "Naz";

var hits = [];

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


#2

Here,

It should make increment of j. So,

j++

You may be interested in seeing your output. Then, add:

console.log(hits);

#3

OMG, :@

Thank you so much, you clearly have better attention to detail than me even though i just downed an entire cup of coffee! Thanks, and have a great day amazing one. :smile: :smile:


#4

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