#6 - Code returns 25 []


#1

Now my return is 25 [ ] one on each line

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

/*jshint multistr:true */
var text = "Hello. My name is Betty. My mother's name was Betty. Her mother named her Betty after a favorite Aunt Betty. Some people think my real name is Elizabeth, but it isn't, it is Betty."
var myName = "Betty"
var hits = []
for (var i =0; i<text.length; i++){
     if(text[i]==='B'){
     for (var j = i; j < i +myName.length; j++){
    hits.push(text [j])     
if(hits.length = 0){
    console.log("Your name was not found.");
} else {
    console.log(hits);
}}}}

Continuing the discussion from #5 - I am getting a number (25) returned:


#2

Line 2, 3, 4 and 8: You miss a ";".
Line 9: Please replace the "=" operator, withe a "==".
This should work.

The "=" operator is an assigment operator. It sets a value to what is left to it.
The "==" operator is a comparison operator. It compares the value on it's left with the value on it's right.


Another operator similar to "==" is the "===" operator.
Differences:
"==": Cares just for the value.
"===": cares for the value and the type.

More on operators: http://www.w3schools.com/js/js_operators.asp


#3

@ajaxwhiz07943,
In addition to what @dimitrispl pointed out
you will have to place
the code-block

if(hits.length === 0){
    console.log("Your name was not found.");
} else {
    console.log(hits);
}

outside of BOTH of your FOR-loops.

The code-block is used to Display the Result if there where any hits


#4

Thank you very much! I did not know there was a difference.


#5

@ajaxwhiz07943,
Have read through
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators