Your second for loop


#1

var text = "hey how are you My name is joseph" ;
var myName = "joseph";
var hits =[];
for(var i = 0; j< text.length; i++){
if (text[i] ==="j"){
for (var j=i; j hits.push(text[j])
}
}
}
My code


#2

Is there anything you would like to ask? It's unclear what the purpose of the thread is.


#3

sorry i want too see what is wrong with my code


#4

Why do you say that there is something wrong with it? Does it not behave like you want? If so, what does it do differently? We can't guess what your code is meant to do, only you know that.


#5

this is the error: It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable.


#6

Then you might want to start by running the code and printing out that array afterwards to confirm whether that is the problem.

If it is, then you might want to add more prints in the code to find out why it isn't reaching the statement that adds characters to the array.


#7

You started your iteration with 'i' and then you jumped to j in your for loop


#8

what do i need to change


#9

its okay i figured it out


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.