Welcome to the Treehouse Community
Looking to learn something new?
Substring 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
Steven Parker220,378 Points
Without 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):
lengthcharacters from a string, counting from the
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.