4. 'Your 'If' statement' problem



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.


Hey @rosie89,

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


I thought it would be something obvious like that.



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.


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


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


please who can help on javascript