Isn't pushing values to the hits array. WHY?!?


#1


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


After spending hours trying to figure out the problem myself to no avail I decided to go back to the "1.What you'll be building" lesson and copied the code to see if it would work. It didn't. Am I missing anything. Please help!


/*jshint multistr:true */
text = "It was the best of times, it was the worst of times, it was the age\ of wisdom, it was the age of foolishness, it was the epoch of belief it was\ the epoch of incredulity, it was the season of light, it was the season of\ darkness, it was the spring of hope, it was the winter of despair." ;

var myName = "Dicke";
var hits = [];

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


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.


#2

According to instructions text should contain value of myName, at least one.

Add "Dicke" to the text.


#3

HAHAHA geez! Thank you so much.


#4

You're very welcome :wink:


#5

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