Trying to complete 5/7 breaks Codecademy


#1

I've looked through every help thread on here to see what I could be doing wrong. Here is my code:
var myName='William';
var hits=[];
for(var i=0;i<text.length;i++){
if(text[i]===myName[0]){
for(var j=i;j<myName.length+i;i++){
hits.push(text[j]);
}
}
}

When I run this, my browser tab freezes and I have to close/reopen it. I am using Chrome. Any help will be greatly appreciated. Thanks!


#2

Hey this may be a bit late but what this also happened to me and what managed to fix it was to replace the "i++" with "j++". It may help stop your browser from crashing.

for(var j=i;j<myName.length+i;i++){
/*switch the "i++" to "j++"*/
for(var j=i;j<myName.length+i;j++){

#3

What's the use of i++ in the second for statement if it states that j < myName.length + i?

Since there is no reason that i should stop in the for statement it is placed in, the i would just go on forever and ever and ever... crashing the browser.

Hope it helped!:smiley:

P.S. What @javarunner33393 said is the correct code to stop it from crashing.