An unwelcome 'undefined' result - why?!


Hey there!
So, when I run my code I find results that are encouraging but still.. not good.
And it's not that I want to fix it, I'm going NUTS trying to find my mistake.
Can someone help me? Thanks!

[ 'M', 'a', 'r', 'g', 'h', 'e', 'r', 'i', 't', 'a', undefined ]


var text = "Io mi chiamo Margherita";

var myName = "Margherita";

var hits = [];

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


I think your problem is literally just

right here you shouldn't have the equal sign, it should just be the less than, <, sign. :slight_smile:


ohhh, thanks! I'm literally both relieved and kind of disappointed :smiley:


Your code is fantastic, and the hardest errors to solve are the one's you barely notice. When that happens, just go through line by line or write pseudo code. I'm glad you got it to work. :slight_smile:


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