6.log it error


#1



/*jshint multistr:true */
var text = ("ddd", "aaai", "wwww", "ssss");
var myName = "Taaaa";
var hits = [];
for (var i = 0; i < text.length; i++)
{
        if (text[i]==="T")
            {
                for( var j = i; j < (i+myName.length); j++)
                hits.push(text[j]);
            }
            {
                if (hits.length === 0){
                    console.log("Your name was'nt found");
                }
                else{
                    console.log("hits");
                }
            }
        
    }

I am getting different output can someone please help
Instead of getting name as my output. I am getting hits as output


#2

A comma separated list of expressions will evaluate to the result of the last expression. Perhaps your text should be something else?

// see for yourself:
console.log(text)

You seem to say that you expect your name to be printed, but none of your console.log's output anything that could be your name (You have two console.log's and they both print string literals)


#3

Yeah I'm getting output as
hits
hits
hits
hits
hits
Where as it should be printing out my letters right?
can you tell me where I'm doing wrong and also correct code for that.
Thank you


#4

Look at your console.log's, is it possible for either of them to print your name?

If not, then you'll have to consider why and how your name would be getting printed and implement that, if that's what you want to happen.

If you think your name should be printed with the current code, then .. well you'd be wrong, but which console.log do you think would have that effect? Or what would be printing your name?

And again, check the value of your text

I'm just repeating myself here, I said the same things last message!


#5

Got you
thank you :slight_smile: