Search Text for your name JS - Success not visible


Hi there!

I'm getting a pass on this sending me to the next step however in neither phase is my name being printed out via the console.log. Any idea why I'm getting an empty array [ ] as my result?

How can I get this to print my name in the console display?
Thanks in advance for for any help!

Stuck here

/*jshint multistr:true */
var text = "hi my name is Alex and Alex is the name!";
var myName = "Alex";
var hits = [""];

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

if(hits.length = 0){
    console.log("Your name was not found!");
} else {


Change the 1 to an i so it iterates over all four letters.


Hi @mtf, I appreciate the reply! However i'm still getting a blank array printed. Any chance it's a bug in CodeCademy? ..or are you getting the name printed into an array when you run??


I think i understand the logic but this is what I'm seeing:


This should be raising a syntax error in the console. We cannot make an assignment in a conditional expression.

hits.length === 0

Be sure you start with an empty array.

var hits = [];


@mtf, nice! I made your suggested changes and it's printing now. Thank you!

This poses a new question as it's printing the first letter postion of the array (name.length times) instead of the actual letters. I'll dig around for solutions :wink:

Appreciate the quick help!!


Sorry, I tend to mete out answers one at a time to give the learner time to discover their mistakes. The last thing to cover is what is being pushed to the hits array. As you have discovered it is pushing the index, not the letter.


will be the letter at index j.


Works like a charm! Thanks again @mtf!!
Sure to see you around these threads :slight_smile:



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