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


#1

/*jshint multistr:true */
var text = ("Hello, Mathias!");
var myName = ("Mathias");
var hits = [];

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

My code doesn't seem to work, i can't figure out what the problem is, please help! :slightly_smiling:

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.


#2

@saihtame

Look here

If you want to put a string inside your text variable, no need of parentheses.


#3

@saihtame,

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

In your first FOR-loop

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

as [initialization] you assign the number Value 0 to the variable i
then in your [condition] you test if the i is greater than the text.length
which is NOT possible !!!


#4

You are completely right, i've just used 30 minutes staring at this code withut noticing this.

Many thanks :smiley:


#5

@saihtame,
This proofs once again...

The time spent on your code, does not tell something about the quality of the code :innocent:


#6

At one point you just get stuck, this is especialy hard for beginners.