5. Your second for loop (what's wrong?)


#1


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.


var text = "Josh testing 123";
var myName = "Josh";
var hits = [];

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


#2

Finally solved. Nevermind =]


#3

I'm getting the same error. How did you solve it?


#4

in my code, I changed:

if (text[i] === myName["J"]) {

to

if (text[i] === myName[0]) {


#5

Thankyou for the reply. I got it!!


#6

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