I need help with this please. Not sure why this doesn't work


#1


Why doesn't this work?

var text = "apsfdoiajpsdoigjbpoiajposidfj GG asdpfoijpoiwejfpoij"
var myName="GG"
var hits=[];
for (var i = 0; i < text.length; i++) {
    if (text[i] === 'G')
        for (var i =0; i<text.length; i++)
        for (var j = i + myName.length; j<i; j++) 
hits.push(text[j])
};
console.log(hits);


#2

can you send a link?


#3

Why? I've already sent the code.


#4

also what does the error say?


#5

mostly so I can go back and see my code for the assignment to compare. I'm not sure if it happens for everyone but when I follow a link it takes me to my assignment not the other persons


#6

for (var i = 0; i < text.length; i++) {
    if (text[i] === 'G') {
        for (var i =0; i<text.length; i++) // what does it mean?
        for (var j = i + myName.length; j<i; j++) {
           hits.push(text[j]);
        }
   }
};

You wrote for loop with same conditions twice, but why?
Also you need to review your second for loop. This loop should starts from that index (var i) where 'G' is found. Because var j = i + myName.length means that your second for loop begins after your name:
i = 30
myName.length = 2
So,

var j = i + myName.length
// equals to
var j = 30 + 2 = 32

#7

It's help to find the lesson's instructions quickly and I can compare your code with mine.


#8

how would this be fixed then?


#9

Please, read my previous post and review your code.


#10

Thanks.

While you're here, how do you fix this:

var understand = false;

while( understand = false ){
console.log("I'm learning while loops!")
understand = true;
}


#11

The while loop loops through a block of code as long as a specified condition is true.

Syntax

while (condition) {
    code block to be executed
}

So, loop starts when condition is true, but inside the loop you need to change condition to false (in your case - understand = false;)


#12

oh. Thanks! That's helpful!


#13

Also condition should retuns boolean value:

while(understand) { ... }

#14

I'm trying all sorts of things, but none of them are working.


#15

try changing it to while(understand === ) instead of while(understand =)


#16

Thank you so much! I'll try that.


#17

Now it doesn't do the infinity loop, but it won't print to the console.


#18

ok I might be able to figure it out with a link but I'm not sure what else I can do without one


#19

I figured it out. Thanks for your help!


#20

no problem. if you click the solved button next to a post it will tell everyone that you figured it out and that you don't need help on this anymore. just letting you know.