Code is same as initial example but doesn't function correctly


So the code runs and I don't get any error messages but my name doesn't print out, it finds the a in rainbow and correspondingly prints out "ainbo but" then all following "a"s are ignored and not printed. Would just like to know why this happens as I checked back and I think the code is the same as the example at the start which didn't stop at the first "E" it found.

Replace this line with your code. 

var text = "rainbows and butterflies unicorns \
called alice fairies with wands magical castles"
var myName = "alice"
var hits = []
for (var i = 0; i < text.length; i++) {
if (text[i] === "a") {
    for (var j = i; j < (myName.length + 1); j++) {
if (hits.length === 0) {
    console.log("Your name wasn't found!");
} else {


Left my comments above.I hope I cleared some things up. Try changing the myName variable to 'Alice' and the alice in the text to 'Alice' as a test.


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