22. Why not "wonderful day".substring(3,6)


I know the answer that the console accepts is "wonderful day".substring(3,7) but why?

if we're looking for the 7th letter, isn't that in position 6 (starting at position 0)?


Hey there,

It might help keeping in mind that the last number in the substring method represents the first character not to include in the returned substring.


To further clarify and more fully answer the question given the above. The reason you would end up using (0,7) despite this seemingly taking the the 8th character, is because the 8th character would be the first character we'd ignore in the given string.

Hope that helps.



thanks so much... that does help. i am somewhat familiar with vba, and the syntax for vba is "(Start Character, Number of characters)", so this was a bit unfamiliar.

thank you for the quick help


No problem!
Glad it all makes sense, would love to make this topic as resolved but I can't, so will wait for a mod to do that for us.

FWIW - if you're really stuck on syntax and why something is the way it is, do check out MDN (https://developer.mozilla.org/en-US/docs/Web/JavaScript) , it continues to be a great one stop shop for me! :smile:


What the @bisepost can do is he can go to the button "Solution" and mark that as the proper solution for the topic. This will not close the topic, but it will essentially mark it as finished.