Your second "for" loop


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.

/*jshint multistr:true */
var text = "My name is Nish. Nish is learning to code.";
var myName = "Nish";
var hits = [];
for (var i = 0; i < myName.length; i++){
    if (text[i] === myName[0]){
        for (var j = i; j < (i + myName.length); j++){


corrected as suggested by @stetim94
for (var i = 0; i < myName.length; i++)

there you need to make change!

i < myName.length;


i disagree with @greentreemee

you need to make a change to your first for loop

you only loop till end myName.length, you need to loop over text


I don't understand. What am I missing?


Thanks I changed the first loop so it loops over text and it works now.


there is a problem with your first loop ^


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