5. Your second "for" Loop - I AM SO STUCK



Every time I run this code, my browser crashes.

/*jshint multistr:true */

var text="Hey my name is Jordan, I love cats, dogs, and did I mention my name is Jordan"

var myName="Jordan"

var hits = []

for (var i=0; i<text.length; i++){
    if(text[i] ==="J"){
        for (var j=i; j<i + myName.length; i++) {


There may be a good reason for that :slight_smile:

If you look at this portion of the code:

The letter being incremented is the j, not the i.

If the i were to be incremented, the code would constantly run to satisfy the condition, the purpose there are for loops and other loops. Since it is a loop, there has to be a condition for the action inside the loop to be executed appropriately, and it will always be satisfied because the i will always increase more than the value of j, thus being an infinite loop.

And you know how complicated infinity can be...


Fixed it! Thanks for the help and the explanation to go with it. Cheers mate!


`var text = "Hey my name is Jordan, I love cats, dogs, and did I mention my name is Jordan";

var myName = 'Jordan';

var hits = [];

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

this worked, change the i++ to j++


What could I have done wrong?


Your code searched for "Amor Foods" in the text and didn't find that's why it gave you the Unexpected token ILLEGAL error!

when trying to find a word in a line of text, that word you're trying to find must be in the text to start with.