How do make it push to 'hits' array?


#1

You heard it... Here's my code:
/*jshint multistr:true */

var text = "Hallo, I am crazy russian haKer and velkom to/ my labratury were seifty is numbur une prijority";
var myName = "Kristijonas";
var hits = [];
for (var i = 0; i < text.length; i++){
if (text[i] === "K") {
for(var j = i; j < (myName.length + i); j++){
hits.push(hits[j]);
}
}
}


#2

I don't your question. Can you clarify?


#3

Oh ok. So basicly when I run this code, it gives me error, saying that I need to make sure, that it is pushing to the 'hits' array.


#4

you should type hits.push(text[j]) in for loop,instead of hits[j]


#6

What am I doing wrong?

/*jshint multistr:true */
var text = "I Letitia love eating chocolate. My name is Letitia.";

var myName = "Letitia";
var hits = [];
for (var i = 0; i < text.length; i++){
console.log(text[i]);

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