What's not working?


/*jshint multistr:true */
var text = "Jacob is a true master of the Sith Order."
var myName = "Jacob"
var hits = []
for ( i=0; i > text.length; i++) {
if (text[i] === 'J') {
for( j=i; j = (myName.length + i); j++){
hits = [];

That up there ^^^ is my code and I keep getting syntax errors and I can't figure out what I'm missing. Please help.


Could I see the error please?


Oops, try again. It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable.

Here it is ^^^


Could it be because

hits = [];

is inside the for loop? Meaningly you emtpy it every loop?

Try placing it outside of the loop? :smile:


Its still doesn't work...


could it be for i?


try changing:

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

> to <


for( j=i; j = (myName.length + i); j++){

= to <

For loops have three parts in their parenthesis (Initialization ; Condition ; Postfix / Increment / Decrement )

If the condition doesn't prove true the for loop will not proceed.


Also follow the advice @sralse mentioned in his comment above.


Ah! It works!! Many thanks!