Really stuck with this exercise


Hi, please can you help me with this "for" loop? This is the error message:

'Oops, try again. 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'

{ for (var i = 0; i < text.length; i++) if (text[i] === 'E') { for (var j = i; j < i + myName.length; j++)

Replace this line with your code.




Needs curly brackets at the end of this line for the codes to execute in between it.

Remove these lines. You must add text variable indexed as j to hits array using push method like this:



Ok I understand. Thank you!! :slight_smile:


I'm still struggling.

var text = "I am Guy, nice to meet you"

var myName = "Guy"

var hits = [];

for (i = 0; i === text.length; i += 1) {
if (text[i] === "G") {
for (var j = i; j === (i + myName.length); j += 1) {

I can't understand what's wrong with my code. Can anyone help?



If you have a problem, please post it in a new topic with your question + error message + code



I'd like to echo @miniapple8888's comment, and also to suggest you reexamine your for loop.

Remember, the syntax for a for loop is:

for (counter = [where it starts counting from]; counter < or > [where you want it to stop counting]; how much the counter should increment by) {}

Are you sure your loop follows this format?



(PS: a friendly reminder that i+= 1 can also be written as i++ :wink:)