5. Your second "for" loop - help


#1


/*jshint multistr:true */
var text = "Her name is Katie \
Katie is a really good person.";
var myName = "Katie";
var hits = [];

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

Well.. I can't find the error and I also don't understand what "This loop will make sure each character of your name gets pushed to the final array." means. Please help me


#2

The aim of program is to find the first letter of your name inside the string text,If it finds it then push all the letters of name to lists array.


#3

here:

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

we loop over text, then to determine our name is present, we compare current character in text (text[i]) to see if it equals myName first character. i will change over time, while the condition should always check current character in text equals first character of your name (myName)


#4

Oh ok thank you for helping me !


#5

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