And if your name have an starter letter in the middle os its? allan - "a"ll"a"n


Search Text for your Name!

If your name is like mine (allan), this exercise wont run correct until you change your name :slight_smile:

var text = "my  is alln, your  is alln, her  is alln";

var myName = "alln";

var hits = [];

for (var i = 0; i < text.length; i++) {
    if (text[i] === "a") {
        for (var j = i; j < (myName.length + i); j++) {

if (hits.length === 0) {
    console.log("Your name wasn't found!");
} else {


you could change your name to Allan and then change your if condition to:

if (text[i] === "A")

this will work, given string comparison is case sensitive.


Thank you, I'll try it on.


you can also replace "a" with myName[0]


true, this will be better (given you don't hard code the letter)


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