Your second "for" loop


#1

Whenever I run it crashes which I'm presuming is because there's an infinite loop, not particularly sure whats wrong, any help is welcome, thank you in advance

var text = "chickens lemons turles Callum, dogs, yellow, pretty cows, likely rainy when tuesday... sleeps, Callum continue tomorrow"
var myName = "Callum"
var hits = []

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


#2

your j for is setting j = to something instead of checking for j <

try something more like this

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

#3

Worked great, Thank you!


#4

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