Log It! It works but doesn't return the right number!


#1


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


No error messages...
But returns

[]

And not [3]

Codeacademy thinks this is right but I don't understand why it isn't returning 3! I wrote my name 3 times!


var text = "Some words some words some more words and my name Grace \
more words and here's my name Grace Grace that's three is that enough"
var myName = "Grace"
var hits = [ ]

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




Thank you!! :slight_smile:


#2

Here:

Use three equal to signs. What you did was to assign.

if (hits.length === 0) {

#3

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