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


#1

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)?


#2

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.

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/substring

--EDIT--
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.


#3

hey,

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


#4

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:


#5

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.