Your second "for" loop


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++); {


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


Hi - Works now! Thanks a lot!


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++); {

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!


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++


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