Stuck on 2nd For Loop


#1

Hello,

here is my code. Help much appreciated!


/*jshint multistr:true */
var text = "The world is happier when Rachael is happier, and Rachael is happier when the world is happier"
var myName = "Rachael"
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]);
}}}


#2

Hello :smile:

Problem is here:

j < (i + myname.length)

Variable myname is simply undefined. Remember that JavaScript is case sensitive!


#3

Hi
I also have the same problem!!!


#4

Oh my gosh!!! I feel so silly. Thank you so much!


#5

You're very welcome :panda_face:

@megamaster65912 can you post here your code?


#6

whats wrong with my code here?

/*jshint multistr:true */
var myName = "Jack";
var text = " I am Jack's Colon, I get cancer and kill Jack";
var hits = [];
for (var i = 0; i < text.length; i++){
if (text[i] === 'F')
{for (var j = i; j < ( i + myName.length;) j++)
{hits.push.(text[j]);
}}}


#7

Here is my text, and it is correct! I hope it helps!
var text = "Elias is awesome! Elias is awesome! Elias is awesome!";
var myName = "Elias";
var hits = [];

for (var i = 0; i < text.length; i++) {
if (text[i] === 'E') {
console.log("I am Elias. I love to say: " + text);
for (var j = i; j < (i + myName.length);j++){
hits.push(text[j]);
}
}
}


#8

What does j mean? I am kind of confused.


#9

j is the variable :slight_smile: