4. 'Your 'If' statement' problem


#1

Hello,

Wondering if anyone has any advice. I entered the following code:

var text = "Hey, how are you? My name is Rosie. I call myself Rosie because that is my name.";
var myName = "Rosie";
var hits = [];
for (var i = 0; i < text.length; i++){
if (text [i] ==='R'){
//Do something
}
}

And got the message: 'Oops! Remember how to check the value of an element in an array? You simply do arrayName[i]'.

I have tried to resolve it using the hint and looking at the code in other posts but can't see anything wrong.


#2

Hey @rosie89,

You put a space between the 'text' and '[i]' here. :smiley:
That makes a problem. :smiley:


#3

I thought it would be something obvious like that.

Thanks!


#4

hey guys you know in, if(text [i] === 'R'), what exactly does the [i] do in this scenario, like what exactly is it purpose. please tell me asap lol.


#5

It's basically saying if the [i] value in the for statement hits a capital 'R', then do something.


#6

oh ok but why do you have to put the "text" next to the [i] in the if statement? Thanks for your help btw.


#7

please who can help on javascript