2nd For Loop


#1


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


I cannot tell what I did wrong. It says - 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,";
var myName = "Jacob.";
var hits = [];
for (var i = 0; i<text.length; i+=1){ 
    console.log(text);
    if (text[i] === 'J'); { 
        for (var j = i; j < (myName.length + 1); j+=1){
            console.log(myName);
            hits.push(text[J]);
        }
    }
} 
//what did I do wrong?//


#2

HI this line remove the ; at the end

 if (text[i] === 'J'); <--

AND

you should at least put once your name inside this variable (In the string)

var text = "Hello, how are you doing today,";

THEN

This line

for (var j = i; j < (myName.length + 1); j+=1)

this part

(myName.length + 1)

you should put + i instead of + 1 and here

hits.push(text[J])

you put J instead of j in the text[]


#3

Hey Marco, I did what you said but it says 'J' is not defined

/*jshint multistr:true */
var text = "Hello, how are you doing today,";
var myName = "Jacob.";
var hits = [];
for (var i = 0; i console.log(text);
if (text[j] === 'J'); {
for (var j = i; j < (myName.length + i); j+=1){
var text = "Hello, how are you doing today,"
console.log(myName);
hits.push(text[J])
}
}
}
//what did I do wrong?//


#4

this line

hits.push(text[J])

you wrote text[J] instead of text[j] the j should be downcase


#5

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