7/7 Passing lesson without printing my name


#1

Hi everyone,
I was wondering if anyone could help me out with my code, since the line

console.log(hits);

at the end of the code, does not print my name, just some empty braces.

Here is my full code:

/*jshint multistr:true */
var text = "bla bla bla sixclaw bla sixclaw.";
var myName = "sixclaw"
var hits = [];
for (var i = 0; i < text.length; i+= 1) {
    if (myName[0] === text[i] ) {
        if (text.substring(i,i + myName.length) === myName) {
            console.log(text.substring(i, i+myName.length));
            hits.push(text.substring(i, i+myName.length));
            }
            }
}
if (hits.length = 0) {
console.log("Your name wasn't found!");
}
else {
console.log(hits);
}

Note:
I added the line

console.log(text.substring(i, i+myName.length));

because i wanted to see, if i made a mistake in the part, where the text is searched for myName.
I guess my mistake is in the line:

hits.push(text.substring(i, i+myName.length));

I just do not know where.

Thanks for helping in advance.


#2

This question is beyond the scope of this project.


#3

I know but i still want to know what my mistake was,
since I pass the lesson, but without completing the task.
Without the

console.log();

line in the middle of my code I would basically have no output.
(expect for this:

[]

)


#4

If it doesn't have to do directly with the lesson, then don't intervene. Your excursions are your own and don't belong in the lesson discourse.


#5

The task was:
"Think about how you might fine-tune this program to make sure it only finds exact matches for your name."
With my code the task is "completed", without returning my name, which should not let me pass the task.
Seen from this perspective it has to do directly with the lesson, and is not an excursion.


#6

Sorry it was meant to be 7/7


#7

There is no lesson checker in 7/7.