Browser Crashing with Code?


#1


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


Code should work fine from what I see. It's just crashing my browser. No infinite loops or anything.


/*jshint multistr:true */

var text = "String Chris String Chris Chris String"
var myName = "Chris"
hits = []

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

Is this my code or is this codecademy?


#2

And how did you determine that there are no infinite loops in that?


#3

Nevermind. Don't know why it was crashing, but I've found the issue. Had to replace j in second for statement with i.

/*jshint multistr:true */

var text = "String Chris String Chris Chris String"
var myName = "Chris"
hits = []

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

#4

(j + myName.length) == Infinite Loop


#5

I accidentally typed j instead of i, lol. My eyes aren't great, and my monitor could use an upgrade. They look similar. X3


#6

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