Help - 7.victoyr


#1


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


my code was accepted, but the only thing on the black screen is "[ ]" and not my name.
can someone find my mistakes?


var text = "bla bla bla bla aline bla bla aline bla"
var myName = "aline";
var hits = [];
for (var i=0; i < text.length; i++) {
    if (myName[i] === "a") {
        for (var j = i; j < i+myName.length; j++) {
           hits.push(text[j]);
        }
    }
}
if (hits.length = 0) {
    console.log ("your name wans't found")
} else {
    console.log(hits)
}


#2

you assign hits.length a value of zero instead of check if hits.length equals zero.


#3

I don't get it :frowning: what's the difference?


#4

in javascript, a single equal sign means assign value. If you want to check if something is equal, use two equal signs


#5

It still doesn't work :sweat:

var text = "bla bla bla bla aline \
bla bla aline bla";
var myName = "aline";
var hits = [];
for (var i=0; i < text.length; i++) {
    if (text[i] === "a") {
        for (var j = i; j < (myName.length + 1); j++) {
           hits.push(text[j]);
        }
    }
}
if (hits.length === 0) {
    console.log ("your name wans't found")
} else {
    console.log(hits)
}

#6

make your name with uppercase letter (Aline) and then also the A in the if condition upper case.

Then there is still a problem in your loop, the condition isn't right, maybe revisit the second forl oop exercise?


#7

also you spelled "wasn't" wrong. i'm not sure that will make a difference, but its possible.


#8

when you put that you are putting it into a variable basically.
you should put it as:
for(var j= I; j < I + myName.length; j++) {


#9

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