Currently engaged in learning on Code Academy, where I am enjoying the process. The topics of push and nested for loops were introduced rather quickly without much initial information. My grasp on the logic is somewhat there, but I would appreciate some help breaking it down...
var text = "Here is a string with the name rick sometimes not always rick and sometimes rick";
//assigning the text string to the variable 'text'
var myName = "rick";
//assigning 'rick' to the variable 'myName'
var hits = [];
//assigning an empty array to store hits
for (var i = 0; i < text.length; i++); {
//for loop starting from zero and incrementing as long as i is less than the length of the entire text string
if (text[i] === "r") {
//if the character at index i is 'r', enter the second for loop
for(var j = i; j < (i + myName.length); j++){
//setting up another for loop starting from i and running for the length of myName which is 4 characters
hits.push(text[j]);
//adding each letter of my name to the hits array
}
}
}
My code is currently not working. Upon adding a console.log statement under the first for loop, it simply prints 84. "console.log("I= " +I)" I realize this may be basic, but I am eager to comprehend the logic behind it. Am I on the right track?