5.Your second "for" loop


#1


I have read over previous post but I cant find what I have inputted wrong. Maybe Im cross-eyed from staring so long... Help!?!


var text="this is text";
var myName="emily";
var hits=[];
for (var i=0; i< text.length; i++){

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


#2

add { after

if(text[i]==="e") // here add {


#3

Thanks!!! my eyes were starting to hurt from staring so long :slight_smile:


#4

var text = " text text text text\
text Priyanka text text Priyanka\
text Priyanka text text text";

var myName="Priyanka";
var hits=[];
for (i=0; i<= text.length; i++){
if ( text[i] === 'P'){
for( var j=i; j< (myName.length + 1); j++){
hits.push(text[j]);
}
}
console.log(hits);
}

This is my code. The code is not pushing anything onto hits. Where did I go wrong?


#5

My code is working. Try this!

var text = " Goutham GVUYU GHVUU";
var myName = "Goutham";
var hits = [];

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


#6

Hey thanks! It worked! :slight_smile:


#7

thanks this worked for me, before i put:

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

then this one worked:

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


#8

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