5. Your second "for" loop



  1. Your second "for" loop

    I thought I did everything but something is tripping me up can someone help me? Thanks.
    the error message is 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's'up \
how's it going.";
var myName = "Ben.";
var hits = [];
for (var i=0; i < text.length; i++) {
if (text[i] === myName[0]) {
   // newArray = [];
 for(var j = i; j < (myName.length + i); j++); {
 newArray = [];
if (hits.length === 0) {
    console.log("You're name wasn't found") ;
} else {

it spits out -- You're name wasn't found


There is syntax error.
When we finish our for loop header we dont put semicolon after it.

for(var j = i; j < (myName.length + i); j++); <- semi colon?

Also look at these lines of code.

newArray = [];

are they necessary ?

Go through instructions and theory again!
if you dont get anything, I will help :slight_smile:


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