I can't see what's wrong


Hey all,

I've compared my code to all sorts of other code on these forums and I can't see anything different with my work.

It keeps saying my second 'for' loop isn't pushing the hits array...

when I try console.log(hits) only brackets appear.

var text = "Phynn is the greatest dog\ around. Phynn is cute and charming for\ a dog.";

var myName = ("Phynn");

var hits = [];

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




The semi-colon-; is an End-of-Statement indicator for the Javascript Interpreter.

The for statement creates a loop that consists of

  • three optional expressions, enclosed in parentheses and separated by semicolons,
  • followed by a statement or a set of statements executed in the loop.


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

You are using this semi-colon-; right AFTER the closing-parenthesis
of both of your FOR-loop definitions,
causing the statements encapsulated in a pair of curly-brackets-{ } NOT being executed.

At the end add an extra
console.log( hits );
to see the result of your code.....



And thanks for responding in a way that makes sense to me. The logic is all there, I simply don't have it engrained yet!

This was probably the most challenging question so far.