Codecademy says my code is right, but output is incorrect


#1

here is my code:

/*jshint multistr:true */

var text = "Well, Kyle's mom's a bitch \
she's a big fat bitch \
she's the biggest bitch in the whole wide world!";

var myName = "Kyle";

var hits = [];

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

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


output looks like this:

[ 'l', 'l', ',', ' ' ]


What am i doing wrong?


#2

You're suppose to look if the first letter of your name appear in text. So myName[i] is incorrect, you need to target K. So try either (text[i] === myName[0]) or if (text[i] === "K").

and wrap i + myName.length in parentheses : for (var j = i; j < (i + myName.length); j++) {


#3

awesome! thank you, virginie_t. I knew it had to be something simple like that...


#4

n/p :wink: