A better explanation of the 2nd for loop


#1

I am completely stuck on this one and have been for a couple of days. I don't want to get the answer i want to better understand it before moving on. What in the world is this excercise trying to get me to do? I am lost on this one. So far i have my 1st name in the var text because they wanted me to put it in there and not sure why. My guess is this excercise is trying to get me to search for my name in a paragraph.....? I think what i need is a better explanation of the excercise. Any assistance would greatly be appriciated.
var text ="michael michael"
var myName = "michael"
var hits = []

for(var i = 0; i < text.length; i++){
if(text[i] === 'M'){
}
}
for (var i = 1; i >= text.length; i--){
}


#2

You're on the correct path, tho!

The purpose of this exercise is for you to be able to search for a string (in this case your name) in a group of text, and have it return to the console.log.

My first suggestion would be to change your var text into a sentence or 2 that includes your name in there.

You do have some more work to do on the code itself, as there are some components missing. I would suggest looking back at the 2 pages before that (4 and 5), as they give you the step by step to build that out.

If you have specific questions or want a check on your additional code, let us know!


#3

please help me with the solution to this


#4

I will be back to give more specifics after i get a chance to do what you suggested. Thanks


#5

I still have no clue how to get to this. Do you have any exa ples so I can gover over. '
for(var i = 0; i < text.length; i++)
{if(text[i] === 'm'){
or(var j = i; j < (myName.length + i); j++) {
hits.push(text[j]);
}
}
}


#6

I'll copy and paste below my full, working example, and you can reverse engineer it to pick up the finer points. Also, I'm by no means a javascript guru, so my code, while functional, may not be optimal. Don't forget that the first part of the section you're in (you're on the 6th part) has the full working script of "what you'll be building" that includes the fully functional end-state as well. Certainly don't hesitate to ask any additional questions, tho!

/*jshint multistr:true */

var text= "Yabba Dabba Doo Steve. Supercalifragilisticexpialidocious Steve is quite awesome. Words.";
var myName= "Steve";
var hits= [];

for(var i=0; i < text.length; i++)
if (text[i] === "S")
{
for(var j=i; j < (i+myName.length); j++)
{
hits.push(text[j]);
};
};
console.log(hits);
if (hits === 0)
{
console.log("Your name wasn't found!");
}
else
{
console.log(hits);
};


#7

Thank you i will give that a try and see what I am doing wrong. This program is kinda weird. It will let me pass the screen before but won't let me pass a little console log section. The console.log part was not the part of the lessons that was hard to understand, that should of been the easy part. So when i got to that part it would not let me go on, i was confused. O well thanks for your help.