7/7 Victory - program still doesn't work despite completion


#1



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

Hi all, course keeps completing but the actual program isn't working :frowning: Any suggestions?


/*jshint multistr:true */
var text = "This program will search through a block of text searching for the word Mark, and when when it finds Mark it will push it into a data array that logs all the frequencies of the word Mark.";
var myName = "Mark";
var hits = [];

for (var i = 0; i <= text.length; i++) {
    if (text[i] === 'M') {
        for( var x = i; x < i + myName.length; x++) {
            hits.push(text[i]);
            }
        }
 };
 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

I am having the same issue. What should the line be changed to? :slight_smile:


#4

at this point in the course i assume you know how to compare operator? Two or three equal signs, if you have more questions please create your own topic


#5

You should push text[x] into your hits array, not text[i]. text[i] continues to equal the same character as you iterate through your "for(var x..." loop, in this case it will always equal "M".