5. Your second "for" loop


#1

var text = "Hey my name is Laura and my surname Marangoni \
I love this name but I also know many other girls \
called Laura.";

var myName = "Laura";
var hits = [];

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

Where am I wrong? PLease help! Cheers.

Replace this line with your code.


#2

Hi after your if condition and for loop statement you should remove the ;

for (var i = 0; i < text.length; i++); <== this one
if (text[i] === 'L'); <== this one 
for (var j = i; j < (myName.length + i); j++); <== this one too

#3

Thanks @wizmarco it worked now!!!


#4
/*jshint multistr:true */

var text = "Sparky is really cool \
I love Sparky very much.  Sparky is the \
best.  Sparky is awesome";
var myName = "Sparky";
var hits = [];
for(var i=0;i<text.length;i++){
    if(text[i] === 'S'){
        for(var j=i;j<i+myName.length;j++){
            hits.push(text[j])
    }
};

I have no idea what I am doing wrong can you please help?


#5

Hi you forgot to close the second for loop


#7

oops i found the problem, sorry.


#8

/*jshint multistr:true */

var text="Hey, how are you \
doing? My name is Rachel and this is \ Sarah.";
var myName = "Rachel";
var hits = [];

for (var i = 0; i >= text.length; i+=1) {
if (text[i] === 'R') {
for(var j = i;j >= (myName.length + i); j+=1) {

        myName.split(",") = hits.push(myName[i]);
        }
}

}

Struggling on this one as well. Its that second for loop having trouble understanding the push the array....