Help with "hits" method


Hey there, can someone explain to me how the "hits" method works, and where/how it fits into my code? I'm really stuck here... Thanks in advance. Below is my code so far.

/*jshint multistr:true */

var text = "Hello, meet James. James likes football. James doesn't like soccer.";
var myName = "James";
var hits = [];

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


hits is not a method, it is an array. You're meant to push letters at the end of it

console.log(hits); #


Not quite like that though, rather you should loop through the text and search for the name.


Oh okay, thanks a heap! I'm new to all this stuff.. :slightly_smiling:


text = "Blah blah blah blah blah blah Eric \
blah blah blah Eric blah blah Eric blah blah \
blah blah blah blah blah Eric";

var myName = "Eric";
var hits = [];

// Look for "E" in the text
for(var i = 0; i < text.length; i++) {
if (text[i] === "E") {
// If we find it, add characters up to
// the length of my name to the array
for(var j = i; j < (myName.length + i); j++) {

if (hits.length === 0) {
console.log("Your name wasn't found!");
} else {

This is the textbook example showing the proper syntax for the second |for| loop