5/7 Your second for loop


#1

I'm not getting this at all, can someone explain to me in steps why its not working, please and thank you.

/*jshint multistr:true */
var text = "Hey, how are you \ doing Jen? My name is John.";
var myName = "John";
var hits = [];
for(var i = 0; i < text.length; i++) {
if (text[i] === "j")
for(var j = i; j < (myName.length + i); j++) {
hits.push(text[j]);
};
};
if(hits.length === 0){
console.log("Your name wasnt found!");
}
else{
console.log(hits);
}


#2

Look at this carefully.


#3

if (text[i] === "myName[0]")

should the code be like this?


#4

No, there should not be the quotation marks around myName[0], for it is not a string. Also, what I was really talking about is the brackets, for you don't have a first bracket.


#5

took your advice, i finally got it working, thanks for helping me out :+1:


#6

here is the newly revised code that was accepted

/*jshint multistr:true */
var text = "Hey, how are you \ doing Jen? My name is John.";
var myName = "John";
var hits = [];
for(var i = 0; i < text.length; i++) {
if (text[i] === myName[0])
for(var j = i; j < (myName.length + i); j++) {
hits.push(text[j]);
}
}


#7

I dont understand this exercise... I'm finding it very difficult to understand it


#8

yea i know what you mean, but im guessing it must be important to learn incase you do need it down the road