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 trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Ayub Muhammad](https://secure.gravatar.com/avatar/91fcaae0e7cddbe01c3d9dfa64ee1a53?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ayub Muhammad
Courses Plus Student 4,345 PointsSubstring Function in JS
Hello everyone! How would I create my own substring function for a challenge? I came off on this challenge asking me to create my own substring! I've researched and tried on my own but haven't figured it out? Can anyone please help me! Thank You
![Ayub Muhammad](https://secure.gravatar.com/avatar/91fcaae0e7cddbe01c3d9dfa64ee1a53?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ayub Muhammad
Courses Plus Student 4,345 PointsThe objective is how do you create YOUR OWN substring function
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,274 PointsSure, but I'm not clear on what a "substring function" would do. I'm expecting the page you saw this on would be likely to provide those details. Can you post a link to it here?
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,274 PointsWithout seeing the actual instructions, I'm going to guess that what you want to do is to re-create the functionality of the built-in "substr" string method. So, start with the functional definition (obtained from MDN):
str.substr(start[, length])
extractslength
characters from a string, counting from thestart
index.
You might begin with a loop that goes from the "start" value and runs for "length" characters, or until the end, whichever is shorter.
Inside your loop, you might take the character from the current index position and add it to a new string being created.
When the loop ends you could return the newly-created string.
So if I have the right idea, that should help you get started.
![Ayub Muhammad](https://secure.gravatar.com/avatar/91fcaae0e7cddbe01c3d9dfa64ee1a53?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ayub Muhammad
Courses Plus Student 4,345 Pointscan you please give me an example of what you just explained
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,274 PointsThere are plenty examples of loops, indexing, and using string properties throughout the courses. I'm only suggesting a way to combine them to create a specific functionality like the "substr" method.
Steven Parker
230,274 PointsSteven Parker
230,274 PointsI'm not quite clear on what the objective is. Can you provide a link to the page you are referring to?