Second for loop problems


#1

A little stuck.
var text=‘Hola mi gente!
Que lo que!’;
var myName = “Rosae”;
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[R])
        }
    }
}

This is the message received.
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.


Your second 'for' loop isn't pushing values to the hits array
#2

hits.push(text[R]) should be hits.push(text[j]);
Also, make sure to have your name in the text. And the text should be in " ", not ’ ’


#3

I understand why it is has to be text[j], but could you explain why (for terarunner)?

Also, both ' and " are fine for having strings


#4
/*jshint multistr:true */
var text='Hola mi gente! \
    Que lo que!';
var myName = "Rosae";
var hits =[];

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

I made the changes but still receiving the below 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.

I also deleted my cache and cookies and restarted the browser but it still displayed the same message.


#5

There is nothing to push, your text variable doesn’t contain your name (Rosae)


#6

Ok I am really racking my brain here.
I have the same syntax as the user above but still receive an error.

 /*jshint multistr:true */
    var text="Hola mi gente! Que lo que!";

    var myName = "Rosae";

    var hits =[];

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

This is the message I receive.

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.


#7

Wow I figured out why the syntax wasn’t working. My string contained words written in Spanish and it did not recognize it. Thank you for all you assistance.