Please help me


#1


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


There is an error in my code. I have no idea what the error is, and I need help finding that out.

This is the error message that it gives me:
"Oops, try again. It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable."


/*jshint multistr:true */


var text = "Hello. How are you doing today? \
my name is Ali Allam.";

var myName = "Ali";
var hits = [];

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


#2

Hi Ali,

This is how your code is suppost to look like:

var text = "Hello. How are you doing today? \
my name is Ali Allam.";

var myName = "Ali";
var hits = [];

for (var i = 0; i < text.length; i++){
if (text[i] === "A"){
if (text[i]
for(var j = i; j < (myName.length + i); j++){
hits.pus
if (hits.length === 0){
console.log("Your name wasn't found!");
}
else {console.log(hits);}h(text[j]);
}

}

}

As you can find you had some troubles with the "for" loop.


#3

Couple of things, var hits = [""]; will data type the array as string as solution needs to be letters and not numbers. I would call the myName[0] and not A given you want the first letter of myName and not A. Also your inner loop is unfinished. You need to complete it noting for(var j = i; j < (myName.length + i); j++) {//insert text.push(); here}


#4

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