Don't understand this for loop?


Oops, try again. Careful: your second 'for' loop should stop when it reaches its current point in the string + myName.length.

/*jshint multistr:true */

var text = "I am from Australia but I live in England. \
I'm 17 years old and my name is Jennifer.";
var myName = "Jennifer";
var hits = [];

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


i will contain the index of the first letter of your name, so then you want to use j to loop from the start till the end of your name (i + myName.length), so you need a condition which involves j and i + myName.length

and then you should increase j, so it can reach the end of your name


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