What`s wrong?


#1

var text="ahmed ahmed ahmed ahmed ahmed ahmed";/*jshint multistr:true */
var myName='ahmed';
var hits=[];
for(var i=0; i<myName.length;i++){
if( myName[i]==='a')
{console.log('y')}
else
{console.log('n')}
}

#2

Well this should print

y
n
n
n
n

does it? Also it is not what the exercise asks to do.


#3

it does, what Specifically it asks :sweat_smile:


#4

Well at the moment you go through your name, letter by letter and when you encounter an "a" you print y otherwise you print a n. Depending on the actual exercise you should rather go through your text instead, again letter by letter (for loop). And when you encounter the first letter of your name ("a") you should do enter another for loop that goes from the current position to the current position + the length of your name and adds any letter that it traverses to the hits array using the .append() method on hits e.g. hit.append(2) would add a 2 at the end of hits.


#5

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