Log it


#1


only print out Tony Once....please help.


 var text = ("tony asd tony afd tony adf tony, tony, tony")
 var myName = "tony"
 var hits = []
 
 for (var i = 0; i < text.length; i++){
    if (text[i] === "t"){
        for (var j = i;  j < (myName.length + 1); j++) {
            hits.push(text[j]);
        }
             
    }
 };
 if (hits.length === 0){
     console.log ("Your name wasn't found!");
 }
 else{
     console.log (hits);
 }


#2

Try changing your text variable so that tony is only mentioned once.


#3

Found my Problem on the 2nd for loop:
for (var j = i; j < (myName.length + 1); j++) {

Change to:
for (var j = i; j < (myName.length + i); j++) {


#4

Glad you found your answer! Good call. I didn't see that.


#5