Your second "for" loop


#1

// This is my code...

var text = ("Frank, John, Chris, John, Rob, Jim, Rob")
var myName = "Rob";
var hits = [];
for (i = 0; I < text.length; i++) {
if (text[i] === "R"){
for (j = i; j < myName.length + i; j++)
{
hits.push(text[j]);{
console.log(hits);
}
}}}

// This is what is printed...

[ 'R' ]
[ 'R', 'o' ]
[ 'R', 'o', 'b' ]
[ 'R', 'o', 'b', 'R' ]
[ 'R', 'o', 'b', 'R', 'o' ]
[ 'R', 'o', 'b', 'R', 'o', 'b' ]

// I am able to pass the lesson but can someone please confirm whether or not I have set this up correctly? Thanks.

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


#2

Returns? You don't have a function, not sure what you mean. If you mean printing, then your code does not print anything at all, you're not calling console.log


#6

If you're saying that I suggested that, then I did not. You seemed to be asking about why your code prints "6". It's not.


#8

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