I'm stuck on #22


#1

I don't know what i'm doing wrong

// Be careful with the substring's letter positions!
"wonderfulday" .substring(5, 7);


#2

Hi try to remove the space between "wonderfulday" and .substring(5, 7) like that ...
"wonderfulday".substring(5, 7);


#3

Remember to type the string exactly as the exercise told you to: "wonderful day".

Also, using .substring(5,7); will print out the 6th and 7th letter - rf.

w o n d e r f u l   d  a  y
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^  ^  ^
0 1 2 3 4 5 6 7 8 9 10 11 12

The 4th to 7th letter of "wonderful day" is obviously "derf".

For the first argument, look at the chart. We know that the 'd' we have to start with is at 3.
For the second argument, you don't need the chart. You just have to count the letters like normal. 7th letter = 7.

So we need to use .substring(3,7);

A simpler way to do this is by taking the numbers, and subtracting 1 from the first number.
4th to 7th letter -> 3 and 7 -> .substring(3,7);
89th to 121st letter -> 88 and 121 -> .substring(88,121);


#4

I'm not sure why this lesson was so confusing to me, but I had the same issue as in the original post. For some reason the wording of the lesson caused me to have to re-think this concept several times.

While I see your point about not needing the chart for the second number, as a beginner I don't like the idea of switching back and forth between using the chart and not using the chart. I finally grasped the concept by taking the "slicing" analogy they use a little bit further. This allows me to stay in the mindset of using the chart.

The slice is made BEFORE each position that you call. When you call position "0" as the first position, a slice is made at the very beginning of the string. When you call position "3" as the second position, a slice is made BEFORE position "3". This means that the resulting substring includes positions 0, 1, and 2 - or the first three letters of the string.

In the exercise, if you call position "3" as the first position, a slice is made BEFORE position "3". Then you call position "7" as the second position, and a slice is made BEFORE position "7". Meaning that the resulting substring includes positions 3, 4, 5, and 6 - or the 4th through the 7th letters of the string.


#5

I had accidentally added a space between the . and substring. Once I took that space out, it was fine! :slight_smile:

I had: "wonderful day". substring(3,7);
and it was supposed to be:

"wonderful day".substring(3,7);


#6

Yes - picture an imaginary line BEFORE each letter. Originally, I couldn't understand why (3,6) didn't work. I hadn't actually read the lesson yet.

We want to spell out "derf".

Picture the imaginary line. It's before 3. So if you were to type the second argument as 6, the line would fall before the "f" and not include that letter. That's why we include the 7, instead, so that the "f' is included.

w o n d e r f u l   d  a  y
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^  ^  ^
0 1 2 3 4 5 6 7 8 9 10 11 12

Derp. I mean derf. :slight_smile:


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.