I don't know where i went wrong


#1

< 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.


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

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 = [];
         newArray.push("Danielle");
         newArray[0]
         };
    }
    
    };


#2

@daniellevg

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
https://discuss.codecademy.com/t/i-passed-this-but-i-just-need-someone-to-explain-the-second-for-loop/30895/2?u=leonhard.wettengmx.n


#3

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