I don't get it


#1

I don't get it.

var text = "hii hii hii hii hii hii hii Rem hii hii hii bla vla bla vla bla Rem vla Rem bla bla.";
var myName = "Rem";
var hits = [];

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

I just don't know what to type. And if i know what to type then i don't get it anyway...


Your Second For Loop Help
Lesson 5
5. your second for loop
How am I using the .push() statement incorrectly?
5. i dont know what to do
How am I using the .push() statement incorrectly?
5. Your second for loop help needed
This nested for loop is causing me massive issues
Loop
Your second "for" loop explanation
Your second "for" loop:
Your second "for" loop
Searching text for your name
Second "For" loop confusion
I don't know how to set the second for loop
Do I understand the second 'for loop' properly?
Neem Help "Your second "for" loop"
#2

Many people are struggling here, lets shorten your text variable a bit so it is easier to explain:

h   i   i   _   R   e   m
0   1   2   3   4   5   6

i put some spaces so we can see it better, then put the index numbers under it (the underscore represent the actual space in the string), so far it make sense right?

so then your first loop:

for (var i = 0; i < text.length; i++)

Will loop over your string, stored in the text variable, so far make sense as well? The moment i is 4, your if statement is true: if(text[i] === "R"), this also make sense?

So now, you want to push Rem into the array, how? Well, it is important to realize that the items are at indexed at 4,5 and 6, agree? At this moment in the loop i is 4, so i + myName.length is 7, so if you do j < (myName.length + i), this will loop over your name. Just make sure to increase j each step of the loop (j++). Hope this helps

If you need more help, post an updated version of your code + question + where and why you got stuck


#3

"So now, you want to push Rem into the array" I don't get this sentence and how it works.


#4

Well, inside your second for loop you still needs to push the hits into an array. j contains the index number of the letter in your string, so text[j] contains the letter you want to push into your array


#5

sorry but my mind is blown. Can you like type it in words so that a 4 year old can understand it aswell from the beginning of the code...


#6

This is the basic explanation. This is difficult, and unless you can tell me where you get stuck, i can't go into more details, then i could write a book with all the details


#7

well i don't get anything of the push thing.


#8

So, you get the second for loop, but not the push?


#9

The push is rather simple, you can push anything into the hits array:

hits.push(what-i-want-to-push-into-array)

#10

but what do u mean by it?


#11

well, you use the second for loop over Rem letter by letter, and you need to store this somewhere, an array is a good place to store it. Push is a function, which pushes something (you decide what) into an array, which is why you made an array in the first place:

var hits = [];

#12

AAAAAAAHhhhhhH thanks! I get it now


#13

nvm i dont get any of it


#14

Well, if you can't specify, i can't help you, you will have to find someone else to help you


#15

this is what I don't understand:

var hits = [];

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

i have done everything well cuz I did get help from programmers because I'm surrounded by them but I just dont get it. Everything from the first part to the last part.


#16

Well, i tried to explain this in my first answer. Did you break down the code with console statement to see what is happening at which stage?

I can't help you any further, you should ask your programmer friends. I can't explain everything, the forum isn't suitable for it


#17

Someone els explained it to me. i get it now. There are a lot of steps which are easy to see if you know what they do and where they are for.


#18

It's a hard lesson to learn. Someone els told me it how it all works in much easier words.


#19

Also on a forum? That is impressive, can i read it?


#20

I am sorry but it wasn't on a forum. I'm at a company that does a lot of programming but I don't work that. It's hard to explain but I'm still in high school. I maybe can explain it like how he explained it if u want.