Not sure if this is correct


#1


6. Log it!


the lesson allowed me to pass but when i save and submit it, it only gives a "[]" is something wrong with it? I thought when you submitted the code it would show you the number of hits or the letters of the name?


/*jshint multistr:true */
var text = "hey my name is michael and michael is not a nice \
person.";

var myName = "michael"

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]);
        }
    }
}
if (hits.length === 0) { 
    console.log ("Your name wasn't found!");
}
else {
    console.log (hits)
}


#2

after reading some forum posts and tinkering with the code i finally got it to work. If anyone was curious as to what I changed, I'll paste it below

/*jshint multistr:true */
var text = "eric eric eric eric .";
var myName = "michael"
hits = [];

for (var i = 0; i < text.length; i++) {
if (text[i] === "m" ) {
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)
}


#3

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