5/7 Second For Loop


#1

I'm not sure what this code is doing, (Why +i in the second for loop?) also there is a unexpected syntax error in output. Also need help after coming back to java after time off, how do I relearn everyhting? Should I just start over

var text = "OJ afsJ.";
var myName = "Jevin";
var hits = [];

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

}


#2

Why use a var keyword here:

var hits.push(text[j]);

you just want to push something to hits, no need to use var keyword

Why myName.length + i? Because j is set to i, so now j will loop from i (the index of your hit) till the last letter of your name, which at i + your names length.

You could start over, but there is no way to reset the js track, but that decision is up to you