How to find my name exactly?


#1

How to find my name exactly?

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/javascript-beginner-en-XEDZA/0/7?curriculum_id=506324b3a7dffd00020bf661

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

var text =" jiwejhfafhsdf \ jsadhfiuhjsdhfsdfhsaduihwkhsf   haoyihuahjkashdfi\ ughajgnfiuaehgjksdf\ giqnwerguhsfd\ j kghirughsjfdg \ hufgbuqiehrgkajhgwuri\ eghasjhgfqiwuklh\ fgdjsmhvbiuhaoyihuaqerhgfk,sdjghilkwerhb\ iulkbdfilghbsldifughiulw\ erhgiluhwebriulghbnfdghgiauhui";
var myName="haoyihua";
var hits=[];
for(var i=0; i<text.length; i++){
    if(text[i]===myName[0]){
        for(var j=i; j<i+myName.length; j++){
        if(text[j]===myName[j-i]){
        hits.push(text[j]);
            } 
        }
    }
}
if (hits.length===0)
{
    console.log( "Your name wasn't found!");
} else{
    console.log(hits);
}

#2

That is exactly what programming is about, being able to think of a solution. Once you have the correct way to solve the problem, coding is the easy bit

So to maximize learning effect, tell me, how do you think this problem can be solved? To only find an exact match?


#3

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