Log it only empty brackets appear


#1

It says I passed the lesson however I am only getting a bunch of empty brackets logged. Here is my code I don't know what I am doing wrong.

var text= "Hello, my name is Maddy. My / real name is Madeline,but I like Maddy."
var myName= "Maddy"
var hits= []

for ( i=0; i if(text[i]=== "M"){
for(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

@iliketochacha,

var text= "Hello, my name is Maddy. My / real name is Madeline,but I like Maddy.";
var myName= "Maddy";
var hits= [];

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

Reference

google search
== the Book ==
javascript [your question] site:developer.mozilla.org

== discussions / opinions ==
javascript [your question] site:stackoverflow.com

== guidance ==
www.crockford.com
http://javascript.crockford.com/code.html << Javascript code-convention
http://javascript.crockford.com/survey.html
http://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript
https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
www.developer.mozilla.org/en-US/docs/Web/JavaScript/Guide