5. Your second for loop - isn't pushing values to hits array


Exercise 5 your second for loop

I'm getting this: "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 = "Hello, what is your name? My name is \
var myName = "James";
var hits = [];
for(i = 0; i > text.length; i++) {
    if(text[i] === 'J') {
        for(var j = i; j < (myName.length + i); j ++) 

I cannot find what is wrong someone please help


Problem is in the condition of the outer loop:

i > text.length

, this loop will never be executed. Because initial value of i is 0 and 0 is not greater than text.length. It should be:

i < text.length

In this exercise you should push to the hits array only the actual letter (text[j]).


thanks that worked well for me


You're very welcome :slight_smile:


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