Section 6 - Completed task, however it doesn't print my name just [ ',', ' ' ]


#1



https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/7?curriculum_id=506324b3a7dffd00020bf661

Hey there, first time here. I have finished this exercise and I get the green complete congratulations message saying its all complete.

However it doesn't actually print my name instead it just prints [ ',', ' ' ] any ideas?


var text = "My name is Kris, its a \ short name. Kris is also the name of a small dagger";
var myName = "Kris";
var hits = [];
for (var i = 0; i < text.length; i++) {
if (text[i] === "K"){
    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)
    };


#2

after foor loop remove ;
for (var j = i; j < (i + myName.length); j++);<=remove it

@kmason123


#3

var text = "Sed ut perspiciatis Bobby unde omnis iste natus Bobby sit voluptatem Bobby accusantium doloremque laudantium, totam rem Bobby aperiam, eaque ipsa quae ab Bobby illo inventore ";
var myName = "Bobby";
var hits= []

for (var i = 0; i < text.length; i++) {
if (text[i] === "B") {
for (var j = i; j < (i + myName.length); j++);{
hits.push(text[j]);
}
}
}
if (hits == 0) {
console.log("Your name wasn't found!");
} else {
console.log(hits);
}

I am having the same exact problem and that first response doesn't make any sense to me.


#4

remove ; after for loop
for (var j = i; j < (i + myName.length); j++);<=remove it

for (statement 1; statement 2; statement 3) {
code block to be executed
}

or

for ([initialization]; [condition]; [final-expression])
statement

@pysolver23029


#5

Awesome, thank you @rcodeman! It printed the result as:

[ 'B',
'o',
'b',
'b',
'y',
'B',
'o',
'b',
'b',
'y',
'B',
'o',
'b',
'b',
'y',
'B',
'o',
'b',
'b',
'y',
'B',
'o',
'b',
'b',
'y' ]

Is that the way it's supposed to look?


#6

go on!!!

@pysolver23029


#7

Thanks, cant believe that little semi colon did that!