5. Your second "for" loop


#1


s

  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]) {
    console.log(text[i])
   // newArray = [];
//newArray.push("Ben"); 
 for(var j = i; j < (myName.length + i); j++); {
			hits.push(text[j]);
 }}
 newArray = [];
    newArray.push('Ben.');
    newArray[0]; 
 }
if (hits.length === 0) {
    console.log("You're name wasn't found") ;
} else {
    console.log(hits);


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


#2

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 = [];
    newArray.push('Ben.');
    newArray[0];

are they necessary ?

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


#3

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