7/7 Help


#1

I am allowed to advance, however the code:

var text = "Hey Troy, I was wondering if I could come over tomorrow."
var myName = "Troy"
var hits = []
for (var i = 0; i < text.length; i++){
if (text[i] === "T"){
for (var j = i; j < (i + myName.length); j++){
hits.push('text[j]')}
}
}
if (hits.length === 0) {
console.log("Your name wasn't found!")
}
else {
console.log(hits)
}

Returns:
[ 'text[j]', 'text[j]', 'text[j]', 'text[j]' ]


#2

replace hits.push('text[j]')
with hits.push(text[j])
(remove the quotes)


#3

I Did it like this.
I created the variable "L"

var text="bla bla bla bla bla bla Patrick bla bla bla Patrick bla bla bla bla bla";

var myName="Patrick";

var hits =[];

for (var i=0; i var l=0;
if(text[i]==="P"){
for(j=i; j<(i+myName.length);j++){
if(text[j]===myName[l]){
hits.push(text[j]);
l++;
}
}
}
}
if(hits.length==="0"){
console.log("Your name wasn't found");
}
else{
console.log(hits);
}