Incorrect syntax


#1

can someone tell me wats wrong with this syntax?

var myName = "Jaylon";
var hits = [];
text = "#jaylon";

for (var i = 0; i < text.length; i++); {
if (text[i] === "J"){

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


#2

You got a disconnector here:

:smiley:

You see it? The disconnector is the semi colon before your first corresponding bracket, and after your loop. That disconnects your loop, making a syntax problem.


#3

i did just now but it still doesn't work


#4

Hi @swagzilla26

If it may help please see the code example below. You were exposed to the syntax gremlins on this one, as well as the semi-colon ragezapper pointed out you also had an additional syntax error further in your code on the second for loop. Updating these along with the case match for the name you want to search and you should be good to go.

var myName = "Jaylon";
var hits = [];
text = "efdst# Jaylon asdf adsf asdf hahsh asdf a##Jaylon"; //updated to match case you are searching for

for (var i = 0; i < text.length; i++) { //remove semi-colon
    if (text[i] === "J"){
        for (var j = i; j < (myName.length + i); j++) { //remove semi-colon after length
            hits.push(text[j]);
        }
    }
}
console.log(hits) //let's view the output

#5

it worked thanks a lot!