Your second "for" loop


#1


https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661#


Can't figure out what is wrong with this code? It comes with this error: 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 = "blah blah blah blah Stefanie blah blah Stefanie";  

var myName = "Stefanie";

var hits =[]; 

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


#2

Hi these lines remove the semicolon

for (var i=0; i<text.length; i++); <-- 
for (var j = i; j<(myName.length + i); j++); <--

You can read more about it here


#3

Hi - Works now! Thanks a lot!


#4

var text = "Hey. how are you \
doing? My name is Jonathan.";

var myName = "Jonathan";

var hits = [];

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

This is my code, and it hits an error. It says that my second for loop doesn't push values to the hits array. Please help!


#5

HI if you read my post you will find wht's wrong with your code...

these lines remove the ; at the end

(i=0; i < text.length; i++); <--
for(var j = i; j < (myName.length+i);i++); <--

then here

for(var j = i; j < (myName.length+i);i++)

instead of i++ it should be j++


#6

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