Your second "for" loop


#1


https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661

please help me!!

var text = "hey, my name is kfir. Nice to meet you";
var myName = "Kfir";
var hits = [];

for (var i = 0; i <= text.length; i++) {

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


#2

The outer loop is attempting to read a character that does not exist. There is no character at text[text.length]. The last index is always one less than the length. Always.

i < text.length

#3

Hi @coursemaster21321

these are your mistakes

var text = "hey, my name is kfir. Nice to meet you";
var myName = "Kfir";

Your code Looks for K in your var text / case sensitive and there is no K

var hits = [];


for (var i = 0; i <= text.length; i++) {

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

// here comes your real mistake after ( i + myName.length we miss a )

    hits.push(text[j]); }
}
}

So if you change that, the show can go on :wink:


#4

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