Victory!


#1

Guys and girls, it says i am all good to complete this part but see below for whats printed, I am not sure this looks right? Any ideas..


var text = "My name is Arron and I love being called Arron.";
var myName = "Arron";
var hits = [];

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

----------- Print ---------------
A
A
A
A
A
A
A
A
A
A
[]


#2

In your first loop, i is being used to represent the characters being scanned in the text variable. In your 2nd loop, j is being used to represent characters from the text that come after 'A' in the myName variable . So hits.push should be scanning text[j] instead of text[i].

You should also change the = sign in your if condition to the === sign.


#3

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