Please help me on "Your Second For Loop" - Search Text For Your Name


My code actually works however I'm not totally understanding a concept. In the exercise in the second for loop we have to use (i + myName.length). How would I know when to include an ' i + ' ? Any insight would be greatly appreciated.

/*jshint multistr:true */
var text = "bla bbla bla blba bll hi, how are you blba bla bla bla bla bla Kevin blab bla hi ahow bla bla bla bla bla";
var myName = "Kevin";
var hits = []
for (var i = 0; i < text.length; i++) {
    if(text[i] === "K") {
        for(var j = i; j < (i + myName.length); j++) {


The 2nd for loop condition is j<(i+myName.length) so that the total # of characters pushed into the hits array matches the total # of characters in the myName variable. If the 2nd for loop condition was only j<myName.length, that would only push K,e,v,i into hits since that is one less than myName.length.



Thank you! Duh, that makes a lot of sense. I really appreciate it.



Glad to help :slight_smile:
I'm currently stuck at object constructors :grin:


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