5. Your second for loop


#1

Here is my code.

var text = "My name is Chris, CHris like to code and Chris \
is a handsome guy!";
var myName = "C";
var hits = [];
for (var i = 0; i < text.length; i++){
if (text[i] === "C"){
for (var j = i; j < myName.length; j++)
hits.push(text[j]);
}
};

If someone could just point out my mistake and educate my feeble mind. Thanks!


#2

Hey @chipsolver23726,

You forgot the two corresponding brackets here. :smiley:


#3

Also in the condition a +i or i+ is needed :smile:

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

#4

Thanks for your help guys! I passed it. I am not sure I am understanding something though. Is it suppose to just output all the letters in my name individually separated by commas in an array?


#5

I would also like to know how really this works.