4/7 "Remember how to check the value of an element in an array? You simply do arrayName[i]"


#1

/*jshint multistr:true*/
var text = "Hi, my name is Maria. Maria is also the name of a winner of a Nobel prize for Chemistry. And there´s also a chinese store called Loja Maria.";
var myName= "Maria";
var hits= [];
for (var i = 0; i < text.length + 1; text=i++) {
if('M' === text [i]) {
}
}
I dont know what I've been doing wo«rong but they keep talking about "Remember how to check the value of an element in an array? You simply do arrayName[i]. Check the Hint if you need help!"


#3

Your for loop is not quite right.

Let's start from the conditional part:

i < text.length + 1

Let's say that text = "Lorem". Length of text is 5. But text[5] does not exist because we start indexing characters from 0. So:

text[0] = "L"
text[1] = "o"
text[2] = "r"
text[3] = "e"
text[4] = "m"

Also third part of your for loop is wrong:

text=i++

this means that after every iteration of your loop you want to change your text value to a number (i++). It does not make sense because you want to iterate through your original text. What you want to do is only increment your iteration value - i,

for (var i = 0; i < text.length; i++) {
    if ('M' === text[i]) {}
}

#4

I always get this error.