For Loops Memory Crash


I am not receiving and syntax errors for codeacademy, but when I run it chrome runs out of memory and crashes. Have I made an infinite loop or unknown error, or is it just an issue with my chrome?

/*jshint multistr:true */
var text = "Blah blah blah blah blah blah blah Ethan";
var myName = "Ethan";
var hits = [];
for ( var i = 0; i < text.length; i++) 
    if (text[i] === "E") 
        for (var j = i;  j < i + myName.length; hits.push("Ethan"))


I just tried switching the second "i" in the second for loop to a 1 and it now reads:
Oops, try again. 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.


Your code..
for (var j = i; j < i + myName.length; hits.push("Ethan"))

wrong for loop syntax

hits.push(something) will be inside the body of your for loop

You have to push letters of your name not name.

for/loop syntax..

for (first part; second part;third part) {
  //your code

third part generally used to be increment/decrement of your loop iteration variable.


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