For Step 5: What is the result supposed to look like?


#1

Hi all,

I've read over many Q&As and think I'm slowing beginning to get it (I must say, I don't think the previous lessons adequately prepares for this exercise). Anyway...

Even though CA says I've passed up to this point, I'm unclear what the results are supposed to look like at this point and therefore I'm confused about the next lessons. My current code is the following:

var text = "Saudi Arabia Josh cut ties with Iran on Sunday, responding to the storming of its embassy Josh in Tehran in an escalating row between the rival Middle East powers over Riyadh's execution of a Shi'ite Muslim cleric, Josh.";

myName = "Josh";
hits = [];

for (i = 0; i < text.length; i++) {
if (text[i] === "J") {
for (var j = i; j < i+myName.length; j++) {
hits.push(text[j]);
console.log(j);
}
}
};

What I see is a list of numbers that must be the array slots associated with the letters:

13
14
15
16
etc.
(The above must correspond to 'Josh')

So...am I only supposed to see the numbers above or am I supposed to see the letters instead?

Best,

Josh


#2

You are seeing only number because on this line

you are printing j which is just numbers that represents the indices of characters in the given text to the console. you can also do

console.log(text[j]);

to see the letters


#3

Many thanks, Rydan!

I either didn't know about that important point. However, my output looks different than the array in #7 ("Victory!") Instead of how it displays the answer:

['E','r','i','c','E','d','d','i','e'];

I get:

J
o
s
h
J
o
s
h
J
o
s
h

Is mine right or wrong?