Search Text Your Name .! Not getting hits


#1

/*jshint multistr:true */

var text = "hey my name is Antariksh!";

var myName = "Antariksh";

var hits = [];

for (var i= 0 ; i < text.length ; i += 1 );

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

hits.push(text(j));
else { Console.log("Your name was not Found");}

}
}


#2

Hey @antariksh_agarwal! Can you read THIS . I will get an anwser to your solution shortly!


#3

Yes i can .! Thanks .!


#4

Ok you missed the whole point here, it was to create an if statement that if it has hits it loops through it and if it dosent it just prints out the later. As said by codecademy...

Under your existing code (and outside all your loops!), set up an if/else statement. If you don't have any hits, log "Your name wasn't found!" to the console. Otherwise, log the hits array to the console.

So when you implement that to code:

for (var a = 0 ; a < text.length; a++) {  <<-- Looping through all of the letters!
    if (text[a] === "C") {   <<-- Basically checking if it has any hits
        for (var b = a; b < (myName.length + a); b++) {
            hits.push(text[b])
        }
    }
    else{  <<-- Else it logs the number
        
    console.log(b)
    }

#5

/*jshint multistr:true */

var text = "hey my name is Antariksh!";

var myName = "Antariksh";

var hits = [];

for (var i= 0 ; i < text.length ; i += 1 )

{
if (text[i] === "A")
{
for (var j = i + myName.length ; j < i + myName.length; j++ );
{
hits.push(text[j]);
}
}

else { console.log(j);}

}

I wrote this code .! it qualifies as an excercise but "25" got printed out.!


#6

thanks, fixed it :slight_smile: thanks for support