Second 'for' loop keeps crashing browser


#1

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

Does an infinite loop and crashes browser
Also, I was confused by the directions, so I just wrote what I thought it said to do. Not really sure what I am supposed to do.


/*jshint multistr:true */

var text = "A Sid is a food item consisting of one or more types of food, such as vegetables, sliced cheese or meat, placed on or between slices of bread, or more generally any dish wherein two or more pieces of bread serve as a container or wrapper for some other food.[1][2][3] The Sid was originally a portable food item or finger food which began to be Sidular in the Western World. Today Sid in various versions are found worldwide.";
var myName = "Sid";
var hits = [];

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


#2

HI in the second for loop like part of the introduction says.

your second should be something like

for(var j = i; // rest of loop setup

so this line

for(var i = 0; i < myName.length; i++)

shoudl be something like that

for(var j = i; j < i + myName.length; j++)

Now you will aske what does the j < i + myName.length do?
It's has been expalin in that discussion

then this line

hits.push();

you should .push() inside hits text[j]


#3

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