6. Log it and 7. Victory...passing with wrong results?


#1

Below is a picture of my code and the results. I received a badge and it says everything is correct but I am note getting my name. Not really sure what is going wrong here.


#2

Hi try to remove the" " to text[j] so Its should be like that

hits.push(text[j])

#4

Mine also... I received a badge and it says everything is correct but I am note getting my name....anybody help?


#5

Try using this ===myName[0] instead of ==="M"
In your first if


#6

Hi try to remove the ; at the end of your for loop


#7

Also I don't know if it will make a difference but put parenthesis around myName.length +i in;
for( var j=i; j< (myName.length +i); j++){
}


#8

for your hits.push(text[j]); you have text[j] in ''. It will treat this as a string instead of holding the iteration.

/*jshint multistr:true */

var text = "My name is Andrew. I live in Austin and have a lot of apples on my farm. My fiancee says Andrew is a good name, but sometimes I think I should go by Drew. I absolutely hate when people call me Andy. I think it makes me sound like I'm still a little kid. So I guess Andrew is okay with me.";
var myName = "Andrew";
var hits = [ ]

for (var i = 0; i if (text[i] === myName[0] && text[i+1] === myName[1] && text[i+2] === myName[2] && text[i+3] === myName[3] && text[i+4] === myName[4] && text[i+5] === myName[5] ) {
for (var j = i; j < (myName.length + i); j++) {
hits.push(text[j]);
}
};
};

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


#9

Great! It's works, Thank you! :smile:


#10

Thanks everyone! I took out the single quotes for myName and got my name to print