6. Log it! (Strange Output that still passes)


#1

Here is the code in totality and I was a little shocked that it passed muster. If you plug it in you will notice that there are multiple outputs that state "Your name wasn't found!" My question is simply, why is this?

/*jshint multistr:true */

var text = "This Item is a certified refurbished Eric. Only select sellers who maintain a high performance bar may offer Certified Refurbished products on Amazon. Certified Refurbished Eric's are tested and certified to look and work like new, with limited Eric to no wear, by a third-party refurbisher. The Eric refurbishing process includes functionality testing, cosmetic inspection, and repackaging. The Eric is backed by a minimum 90-day warranty, and may arrive in a generic brown or white box. The refurbished Eric ships with a charger and cable, but does not include headphone, food, or manual. Accessories may be generic and not directly from the Manufacturer."; 
var myName = "Eric";
var hits = [];
for (var i = 0; i < text.length; i++) {
    if (text[i] === "E") {
        for (var j = i; j < i + myName.length; j++) {
            hits.push(text[j]);
if (hits.length = []) {
    console.log("Your name wasn't found!");   
}
}
}
}

By the way, how do I quote code? I read this earlier, but I've forgotten.


#2

To format your code to make it visible:
1. Paste your code.
2. Select all of your code.
3. Do Ctrl + Shift + C (Windows) or CMD + Shift + C (Mac OSX) to format your code.

OR

1. Paste your code in.
2. Insert 3 backticks (`) before and after your code:

```
Code goes here
```

#3

if (hits.length = []) {

Try making it
if (hits.length === 0){