Need help on 5. Your second "for" loop


#1



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


I don't know why I keep getting this error message. I've checked other question and I still don't know why :confounded:
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.


/*jshint multistr:true */

var text = "blah blah blah blah blah\
                blah James blah blah blah James\
                blah blah blah blah James";
var myName = "James";
var hits = []

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


#2

Hm... the greater than should be lesser than actually/oposite @ragingamer333


#3

I changed it and I keep getting the same error message


#4

@ragingamer333,

for ([initialization]; [condition]; [final-expression]) {
   statement
}

In you 1st FOR loop you initialze i to the number Value 0
then in your condition you are testing if i is =greater than= text.length
That will never happen......

I would also like to point to the fact
that if you initialize a variable to use the var keyword.....
like

for (var i=0; i < text.length; i++) {
//or
for (var j = i; j < i + myName.length; j++) {

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for


#5

After you change that it 100% works for me... can you post your code? Make sure you didnt change anything from original code.. just the signs from > to < @leonhard.wettengmx.n same time post wow..


#7

/*jshint multistr:true */

var text = "blah blah blah blah blah\
blah James blah blah blah James\
blah blah blah blah James";
var myName = "James";
var hits = []

for (i=0; i > text.length; i++) {
if (text[i] === myName[0]) {
for (j = i; j < myName.length + i; j++) {
hits.push(text[j])
}
}
}
still same error message


#9

@ragingamer333
you didnt change the signs at all!

Its suppose to be > not <


#10

I just tried both ways, when I do it, I keep getting the message. It irritates me :persevere:


#11

Ok @ragingamer333 dont get irritated... show me the code i told you to do.. (dont forget to include the one i changed it < to >)


#12

No matter what way i do it, I keep getting the same message

(Original version)

/*jshint multistr:true */

var text = "blah blah blah blah blah\
blah James blah blah blah James\
blah blah blah blah James";
var myName = "James";
var hits = []

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

(Corrected version)

/*jshint multistr:true */

var text = "blah blah blah blah blah\
blah James blah blah blah James\
blah blah blah blah James";
var myName = "James";
var hits = []

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


#13

Your still not listening to me @ragingamer333 choose your original version BUT, change the first for loop from > TO < So:

Change THIS

To


#14

OOOOOOOOOOOOOOOOH! lmao I was changing the second one hahahahahaha thx for the help tho


#15

my code doesnt work either please help!
var text = "harrison is an utter beast like a cow, harrison can eat 10 mod pizzas in 20 seconds"
var myName = "harrison"
var hits =[]
for(var i = 0; i < text.length; i++)
{
if (text[i] === "h")
{
for(var h = i; h < i + myName.length; h++)
{
if (text[i]
{
hits.push(text[h]);
};
};
};
};


#16

You forgot the other parenthesis