What's not working?


#1

/*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 = [];
hits.push(text[j]);
hits[0];
}
}
}

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


#2

Could I see the error please?


#3

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 ^^^


#4

Could it be because

hits = [];

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

Try placing it outside of the loop? :smile:


#5

Its still doesn't work...


#6

could it be for i?


#7

try changing:

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

> to <

and

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.

--Edit--

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


#8

Ah! It works!! Many thanks!