6 -Did I code wrong?


EDIT: Nvm a few next later they say its isn't perfect and what I encountered is a possibility!

My name is harel - 5 letters.
in this exercise we push name.length to the array when it hits the first letter of the name.

when i coded i used "Hi my name is harel and im 21. as I said my name is harel so yeah.. thats that!"
when i wanted to see what is in my array i noticed that after every "h" the code send 5 letters to the array but not only the letters from my name. in my text I used "thats that!" and the h,a,t in "that" got sent to the array too.
did i code wrong or just a coincidence and the developers haven't thought about this possibly?

var text = "Hi my name is harel and im 21. as I said my name is harel so yeah.. thats that!";
var myName = "harel";
var hits = [];

for (var i=0 ; i < text.length ; i++) {
    if (text[i] === "h") {
    for (var j = i ; j < (myName.length + i) ; j++) {


Well you discovered the flaw of the logic....
How would you change the flow so that only your name is in the hits Array.


Probably use a function like in the rock paper scissor exercise where if the first letter is h but the next letter is not a then it will continue to search.

your thoughts?

well a new question after i finished with the rest of the exercise - the array became blank. then i remove this block of code it returns. why?

  if(hits.length =0) {
        console.log ("your name wasn't found!");
    else    {



In an IF condition you will have to
use a comparison operator
instead of you using an assignment operator....