Please help me


#1

Hello.
Please explain all this second 'for' loop better.I can't understand what these codes do.Especially the .push method(how it works and what it does).
I wrote a code actually but i'm not sure what they do.This is it:
/*jshint multistr:true */
var text = "blah blah blah balh blah blah blahj Thanasis blahblahblah blah blahb lbha blah blajhThanasis blajh blah blah";
var myName = "Thanasis";
var hits = [];
for (var i = 0; i < text.length; i++) {
console.log
if (text[i] === "T") {
for (var j = i; j < (myName.length + i) j++) {
hits.push(text[j]);
}
}
}
Result says"ErrorSyntax Unexpected token"
I've tried everything


#2

I haven't run the code, so if the problems persist after my suggested fix, please post an updated version of your code. The code looks fine except for one missing semi-colon in this line:

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

with fix:

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

semi-colon is j++

for next time, use one of the two following options to make your code/indent is visible:

select your code and press ctrl + shift + c (or cmd + shift + c if you use a mac)

if this instructions are unclear, you can also insert 3 backticks before and after your code, like so:

```
<p>visible</p>
```

the backtick is located above the tab key on your keyboard


#3

Jesus Christ.That was it.Thank you so much.Been stuck for over an hour.AAs for the backtick...I'm sorry you mean make it more visible in a post?


#4

Well currently your code looks like this:
var text = "blah blah blah balh blah blah blahj Thanasis blahblahblah blah blahb lbha blah blajhThanasis blajh blah blah";
var myName = "Thanasis";
var hits = [];
for (var i = 0; i < text.length; i++) {
console.log
if (text[i] === "T") {
for (var j = i; j < (myName.length + i) j++) {
hits.push(text[j]);
}
}
}
however, if you format it, the indent will show:

var text = "blah blah blah balh blah blah blahj Thanasis blahblahblah blah blahb lbha blah blajhThanasis blajh blah blah";
var myName = "Thanasis";
var hits = [];
for (var i = 0; i < text.length; i++) {
    console.log
    if (text[i] === "T") {
        for (var j = i; j < (myName.length + i) j++) {
        hits.push(text[j]);
    }
}
}

and if you use the backticks, it will even show some nice coloring


#5

Ah ok.Thank you very much