I do not understand this can some one help me plz! much appreciated and thank you!


#1

/*jshint multistr:true */
var text = "Hey my Name is Marc,Marc Poinson.";
var myName = "Marc";
var hits = [];

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

if (text[i] === "M") {

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

hits.push(myName.text[M]);

}

}

}


#2

Which exercise are you on? 5/7?

Next, are you failing this lesson and that's why you're asking for help?
Or do you simply not understand the concept that the lesson is trying to show?


#3

both and yes it is 5/7


#4

ALRIGHTY LET'S GET TO CRACKING!!!

Problem Area(s):

Let's check out this line of code real quick:

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

for loops are best used in alphabetic order

your first for loop will have the iterating variable of "i", the next loop will have a "j", and the next one after that would be "k" as far as you would need to do you would increment the letter by 1 to the next in the alphabet. This makes reading and writing for statements much easier.

My assumption where you were going with that for loop was to increment the letter in your name, but sadly that's not how you should go about that. Actually the whole second for loop should look very dissimilar to the first. as the following code should explain.

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

Understandably you must be thinking "What in the pooperscoops am I looking at?"

Explaination:

First of all lets break down the for loop real quick into three sections.

Initialization:

var j = i;

you are saying that at this very point in the first loop, I want to start where the i stopped to run my if statement. For right now you can think of this as the numeric value of position for which letter the "i" left off at.

Condition Statement:

j < (myName.length + i) ;

Right now is where the code is saying. "Hey while I am wherever i currently is, but I'm less than the length of the string that is myName, I'm going to pass the ok and move on to the next condition.
In essence this is telling you where your argument currently is, and as long as it is still doing in the parameter of the code above it will keep running.

Increment / Decrement:

j++

I will now increment by this much (in this case just 1) and I will wait for the Condition Statement to say that I'm good to increment again.

This is the last step prior to executing the code you put in, and it's going to the next letter in your "myName" string.

Solution:

if (text[i] === myName[0]) //myName[0] could be interchanged with "M" (The first letter of your name)
{       
    for(var j = i ; j < (myName.length + i) ; j++)
        {
            hits.push(text[j]);
        }
}

I hope this helped. If you have any questions about anything else please don't hesitate to Message me (Clicking my icon and pressing "Message")

Your friendly neighborhood coder,
-LoLMaN


#5

thanks a ton when ever you can finish is fine im just gratefull im getting help
before this it was easy and then stuff went downhill 5/7 thank you very much


#10

lolman's response was very helpful to me.

I can kinda see what this lesson is trying to show me, but thank you for breaking things down and showing why we're doing what we're doing and what exactly is going on.


#11

Glad to help, loops, and if statements are my specialty (seeing as I haven't coded long enough to have a perfect grasp on classes or objects). But if you have any questions don't hesitate to send me a message and I'll help you out to the best of my ability.


#19