Second "For" Loops Error


This pops up when I hit save and quit and I don't know what it's trying to tell me to change. It says "
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 = "text text text text text";
var myName = "Tracer";
var hits = [];

for (var i = 0; i > text.length; i++) {
    if (text[i] === "T") {
        for (var x = 1; x < i + myName.length; x++); {
    } else { 


On line 1, your name doesn't appear anywhere in the text string. You need the myName variable to appear in the text string at least once for the 2nd loop to execute. If "Tracer" doesn't appear in the text, what would make the 2nd loop execute?

In your 1st for loop, you write i > text.length, instead of <. This makes it look for a value greater than the length of your text string. It will never look for anything less than 24 characters long.

You have assigned x to have a value of 1. It should be x=i. What you're trying to do is use this loop to push the text characters from your text string into your hits array, if it comes across a "T". Also, remove the semicolon after x++) in the 2nd loop.

I'm a little confused by this last part. Did you leave something out?


For the last one I didn't leave anything out, I haven't gotten to the "else" statement yet. Also I don't understand what you mean by "On line 1, your name doesn't appear anywhere in the text string" because I declare the myName variable on the 4th line.


This means for this exercise, the word Tracer has to be part of your text string. Like so:

var text= "text text Tracer text text"


this will never find a T in your text string.


Oh! I understand, thank you. Although now it says "Make sure you're pushing letters to the hits array!"


Change this to hits.push(text[x]);


Thank you for your help


Glad it worked out :slight_smile:


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