What is wrong with my 'loop'?


#1

/*jshint multistr:true */

var text = "Ever since Victor was introduced to CodeAcademy,\
learning Javascript has been tremendously fun for Victor. CodeAcademy is a  recognised interactive platform for learning how to code. Victor has learnt alot since he started using the app. Victor is planning to set a similar platform for Victor's friends";
var myName = "Victor";
var hits = [];
for(i = 0; i > text.length; i =+ 1){
    if(text[i] === myName[0]){
     for(j = i; j > i + myName.length; j ++){      
         hits.push(text[j])
         
    }
    }
}

I keep getting this message:
Oops, try again.
It looks like your second 'for' loop isn't pushing values to the
hits array. Make sure it's working properly and that myName's text
appears somewhere in the text variable.

Can some please tell me what am doing wrong.

Replace this line with your code.


#2

i see several problems, the first one in your first for loop:

for(i = 0; i > text.length; i =+ 1)

i > text.length? i is zero, your text is much longer (lets say 200). So the condition is false:

0 > 200

it should be the other way around:

i < text.length

this way, i will increase until it looped over the entire text string. also, to increase i, use i += 1, otherwise you will get a infinity loop.

What goes for your first for loop, also goes for your second for loop, you use > instead of <


#3

@stetim94 YOU ARE THE BEST. Thank you so much. Problem solved first time.