Passed, but does not print name


#1


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


My code finishes, but the console logs "Your name wasn't found!" when my name is in var text twice


/*jshint multistr:true */
var text = "Jimmy is going to see Katy in 9 days.\
Jimmy is very excited to see Katy, and can barely hold his excitement."
var myName = "Jimmy"
var hits = []
for (i=0; i < text.length; i++) {
    if(text[i] === "J") {
        for(j === i; j < i + myName.length; j++) {
            hits.push(text[j]);
        }
    }
};
if (hits = []) {
    console.log("Your name wasn't found!")}
else {
    console.log(hits)};


#2

because in this line of code:

if (hits = [])

you assign a empty list value to hits, instead of comparing, use two equal signs to compare


#3

Now gives me "ReferenceError: j is not defined" isn't j just an iterator, that I have defined as j === i

/*jshint multistr:true */
var text = "Jimmy is going to see Katy in 9 days.\
Jimmy is very excited to see Katy, and can barely hold his excitement."
var myName = "Jimmy"
var hits = []
for (i=0; i < text.length; i++) {
if(text[i] === "J") {
for(j === i; j < i + myName.length; j++) {
hits.push(text[j]);
}
}
};
if (hits == []) {
console.log("Your name wasn't found!")}
else {
console.log(hits);}


#4

in your second for loop, you should the value of i to j:

i = j

i don't know why you decided to compare there


#5

Me either, lol! Thanks for the quick help!!!


#6