7. Victory: Browser window problem


#1


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


I can pass the assignment, and there is no error message. Still, the "browser window" only shows the 2 brackets [ ] from the hits array. No letters or anything. Why?


/*jshint multistr:true */
var text = "Hello my name is Louis. What is yours? \
            Louis is a great name!" 

var myName = "Louis"
var hits = []

for (i = 0; i < text.length; i += 1) {
    if(text[i] === "L") {
        for (var j = i; j < myName.length +i; j++) {
            hits.push(text[j]); 
        }
    }
}

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

else {
    console.log(hits);
}


#2

this line:

if(hits.length = 0)

you set the length of hits to zero, instead of comparing the length of hits with zero


#3

But what do i have to write if i want to compare the length of hits with zero, then?


#4

i was hoping i didn't need to explain that, already in the first track assigning (single equal sign) and comparing (2 or 3 equal signs) variables is explained.


#5

Thanks. I actually discovered that 2 seconds ago, after i wrote to you. Sorry, i need to be more patient.


#6

it is, hm.. not sure what the right word is, fun? to see how i sometimes try to push people in the right direction, by showing them there mistake, but rather then take a moment to think about this, and how they could solve it. they ask a follow up question rather quickly.


#7

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