Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoseph Quintiliano
Front End Web Development Techdegree Graduate 14,338 Pointswhy would the substring parameters be (0, 3) and not (0, 2) if i only want to return the first three letters?
day => day.substring(0, 2) was incorrect but (0, 3) was right
3 Answers
Travis Alstrand
Treehouse Project ReviewerThis is happening because when using substring, the second number we provide is excluded. So using (0, 2) would only return index 0 & 1
. Using (0, 3) would return index 0, 1 & 2
.
You can read more on it here
Also, check your order of your =>
you'll want it to be >=
.
Steven Parker
231,268 PointsAccording to the MDN page for substring(), it returns the part of the string from the start index up to and excluding the end index. Another way to think about is arg2 - arg1 = how many
.
So, with the values of 0 and 3, you get the characters at indexes 0, 1, and 2, but not 3. That's 3 letters.
With the values of 0 and 2, you only get back 0 and 1 (just 2 letters).
Update: I think Travis might have misunderstood part of the instructions. Your use of =>
is correct for creating an arrow function to pass to the map() method. The >=
operator would be for a comparison expression.
Travis Alstrand
Treehouse Project ReviewerI was mistaken regarding =>
thank you for catching me on that Steven Parker !!
Joseph Quintiliano
Front End Web Development Techdegree Graduate 14,338 PointsYoure the man, thank you. you would think we wouldve had to use a bracket before the first parameter because of calc lol