5.Error message says I'm missing a ) and it's not printing out, what am I missing?


#1

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

I've followed all the instructions and combed through other people's posts, and it should be printing, but I'm just getting the error message

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

Can someone please tell me what I'm doing wrong, I've gone over it over and over and I'm just not finding it.


var text = "My name is Olivia. I used to think Olivia
 was a special name, but then I met more people 
named Olivia. Olivia isn't so special now.";

var myName = "Olivia";

var hits = [];

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


#2

This loop won't run with i==text.length. Using i<text.length will let your loop scan all the characters in the text.


#3

Omgosh, thank you, you're amazing, not sure why it accepted it earlier in context, but it fixed it, thank you so much, I would've missed that.


#4

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