5.Your second "for" loop help


#1

/*jshint multistr:true */
var text = "Bryan Bryan Bryan";
var myName = "Bryan";
var hits = [];
for(var i = 0; i if ( text[i]==="b") {
for(var b = i; b<(i +(myName.length + i); b++) {
hits.push(text[b]);
hits[0];
}
}
};
and I get SyntaxError: Expected ')' can someone help me Please


#4

your 'for' loop and 'if' statement is collapsed with one another do make the right changes in the first 'for' loop and 'if' statement.
And then in the second 'for' loop you made a slight mistake in the condition .You have to mention 'i' is greater than b plus your var.length and remove the unnecessary brackets between them and at the next statement you need to make it count your myName var so place it in inside of hits.push(); and remove the hits[0]; .Clean these things you will get the right thing.I hope this will help you. If you are not clear below there is a reference code for you to understand.Have a nice day

/*jshint multistr:true */
var text="Amy,Amy";
var myName="Amy";
var hits=[];
for(i=0;i<=text.length;i++){
if(text[i]==='A'){
for(j=i; j< i+myName.length;j++){
hits.push(myName);

}

}

}


#5

@ devmaster 74184***Your first For loop is missing a parenthesis before the curly bracket


#6

@devmaster74184
There are a few problems, but here's the first one:
Where you had you var text, you need to put in more than just your name, try:

var text = "My name is Brian. Brian is a cool name. I bet you wish your name was Brian."

Remember, punctuation, spelling and case-sensitivity plays a big part in Java Script. If you intend to become a "coding champ", remember you capital letters for names, things, places and the beginning of sentences.

When you made your first loop, you did not if include a space between the "for" and the bracket that comes before "var".

I could go on and on, but let me just give it to you the way it should be done:

/*jshint multistr;true */
var text = "My name is Brian. Brian is a cool name. I bet you wish your name was Brian!";
var myName = "Bryan";
var hits = []
for (var i = 0; i < text.length; i++) {
if(text[i] === "B") {
for (var j = i; j < (myName.length + i); j++) {
hits.push[j];
}
}
}
console,log(hits);

That should be correct. If your problem continues to persist, ask either me or one of the Code Academy Moderators for further assistance.


#7

Hi,

Can anyone see where I'm going wrong please??

/*jshint multistr:true */

var text = "hey, how're you doing? My name is Adam, and \
blantantly ripped off the Adam text.";

var myName = "Adam";

var hits = []

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

}

}
console.log(hits)


#8

That code doesn't seem correct. You spell Brian 2 different ways. and at the end you put a comma instead of a period after console.. as in console.log