Another "Won't Push" topic


#1

Code:

/*jshint multistr:true */
var text = "Luke, heltzer, jow, ass";
var myName= "Luke";
var hits=[];

for (var i=0; i<text.length; i++); {
    if (text[i] === "L") {
        for (var o=i; o<myName.length + i; o++){
    
        hits.push(text[myName])
        }
    }
    else{
        
    }
}

As the name states, my second 'for' loop isn't pushing values. Can anyone tell me what's wrong?


#2

@rovinion

Your code is missing a lot of things. It should look something like this:

text = "Luke, heltzer, jow, ass";
var myName= "Luke";
var hits=[];

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

}
}
console.log(hits);

Suggest going over the whole module again, slowly...

Hope that helps.


#3

actually his code got wrecked by not using the code formatting, this is what was actually posted and as far as I can see the problem is the semicolon here:

for (var i=0; i<text.length; i++); {

This is a link about conditions but it applies to loops as well: