For Loops Memory Crash


#1


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


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"))
        ;


#2

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.


#3

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

Point1.
wrong for loop syntax

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

point3.
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.


#4

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