Lesson 6 Crashes my browser, doesn't output text properly


#1

I run this, and it crashes my browser. I more or less copied the format directly for the example at the beginning. What do you think I'm doing wrong?

Thanks for your help!

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

/*jshint multistr:true */

text = "Let's try this search, Nate.";
var myName = "Nate";
var hits = [];

for (var i = 0; i < text.length; i++) {
  if (text[i] === "N"){
      for (var j = i; j < (myName.length + i); j++){
          hits.push(text[j]); 
      }
  } 
}
if (hits.length===0){
    console.log("Your name wasn't found!")
} else {
    console.log(hits);
}

#2

Well first off you need just three = not four so it would be hits.length === 0. If I had to guess that would be the problem. Also, your set up above that seems to be off in some cases like instead of

it would seem you would need to have j < (myName.length + i);


#3

Thanks! Fixed these but it still crashes :frowning:


#4

Fixed the post! Closing :slight_smile:


#5

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