I don't know where i went wrong


< I don't know what I am doing wrong. I've tried so many times that i don't know what in the code is good or wrong. Could someone describe what a loop exactly does, so that i understand why my code is wrong. And give me a hint were i did get wrong. Thank you.


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.

/*jshint multistr:true */

var text = " Hello, my name is Danielle, how are you doing? My name is Danielle, people call me Danielle but sometimes Daan.";

var myName = "Danielle";

var hits = [];

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



As you have your 2nd FOR-loop
at every iteraton of the FOR-loop you create an =empty= Array
and then pushing-in 1 character....

Your expected to push the found characters into the hits Array !!!1

       for(var j= i; j < i + myName.length; j++) {
          hits.push( text[j] );

you might want to read


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