5/7 This makes no sense


var text = "c f diedhwdonc 3whfcnown Dan101iel ijcnoennd3 Daniel cec coenconr cDanielwnc nwnwcccncw"
var myName = "Daniel"
var hits = []
for (i = 0; i < text.length; i = i++){
if (text[i] === 'D'){
for (var j = i; j < (i + myName.length); j++){
every time i run this i get an infinite loop of death even though my loop looks the same as everyone else's. What am I missing


should just be,


The closing braces can all have the semi-colons removed, as well. They are not part of for or if statement syntax.


i = i++

That's not right. "i++" is actually the exact same thing as "i = i + 1" so you're not allowing your i to iterate, instead it's confusing itself and won't work properly.


Confound it @mtf. I work so hard!


I know how you feel...


then why did that work on the prev lessons


Let's say i is currently at 0. The code body executes, then refers to this expression:

i = i++

What value will i become?


which will be 1, so it will appear to work. But we overlook what i++ really is:

    // is same as
        i = i + 1
    // or
        i += 1

so we don't need an assignment. The value is incremented on the fly.


Im still not sure why i=i+1 works but not i = i++


It's a double assignment that looks like this to the compiler:

i = i += 1

would be one explanation.


ok, btw any reason you get the number of characters in your name x the amount of times your name is there, i got 18, instead of getting your name in the console or the number of time it found your name


The program is storing letters, not the full name, so the count of the array is the number of letters. Divide that by myName.length for a found count.

Also, remember the program deliberately only matches the first letter so 'Daniel' and David ' will both be written to the array.

The name says, "Search text for your name" but in actual fact, it's really 'search text for the anything that starts with the first letter of your name.' We are encouraged to work at ways to improve this project, but on our own.