How do I get this to work?


#1


Search Text For Your Name


It says test is not defined.


/*jshint multistr:true */
var text = "Hey how are you Alex?\
Do you want to see a movie Alex?";
var myName = "Alex"
var hits = [];
for (var i = 0; i < text.length; i++){
 if (text[i] === 'A'){
 for (var j = i; j < (i + myName.length); j++){
     hits.push(test[j]);
 }
 }
} 
console.log(hits)


#2

Hi this line

hits.push(test[j]);

you wrote test[j] instead of text[j]


#3

Thanks that worked!!!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.