6/7 It lets me get into the next step but I didn't understand it really well


#1

/*jshint multistr:true */
var text = "Alfredo will play football in two days. Alfredo \
also likes paintball. Alfredo was sick today"

var myName = "Alfredo"

var hits = []

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

if ( hits.length === 0) {
console.log("Your name wasn't found!");
}
else {
console.log(hits);
};

Here is the code, Thanks for the Help.


#2

Hi @alfre360

What didn't you understand ?


#3

You are looping through the text sentence finding any word that contains an A, if you find an A anywhere in the whole sentence you then take all the letters in that word that contains the A and push each one of the letters in that word into your hits array. This is a flawed solution since it only works if your name is the only word with A in it. I hope that helps, if you are still confused I can explain further :).


#4

Sorry for not specifying, I am fine now thanks for the help! @onepunch_man @edwin0258