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


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++) 


can you send a link?


Why? I've already sent the code.


also what does the error say?


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


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++) {

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

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


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


how would this be fixed then?


Please, read my previous post and review your code.



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

var understand = false;

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


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


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


oh. Thanks! That's helpful!


Also condition should retuns boolean value:

while(understand) { ... }


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


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


Thank you so much! I'll try that.


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


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


I figured it out. Thanks for your help!


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.