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

JavaScript JavaScript Foundations Strings Methods

Mark Lovett
Mark Lovett
15,853 Points

Why doesnt work? quick.charAt(11);

var tenthCharacter = quick.charAt(11);

This prints r which is the 10th character of the string

3 Answers

Jacob Miller
Jacob Miller
12,466 Points

If you weren't aware, a space is also a character. So since they want the 10th character, and you start counting at 0, it should be charAt(9), because that is the 10th character if you start counting from 1.

var tenthCharacter = quick.charAt(9);

I know in ruby counting starts at 0

So you have to train your brain that 9 is 10 -- 10 is 9 and so on.

Edited - had it backwards.. lol

Mark Lovett
Mark Lovett
15,853 Points

Below returns nothing because it is the space between the k and b which is the 10th character (if spaces are counted as characters) . I see. Thanks!

var quick = "The quick brown fox jumps over the lazy dog";
 console.log(quick.charAt(9));
Dave McFarland
Dave McFarland
Treehouse Teacher

Hi Mark Lovett

There's a special way to format code for the forums. I fixed it in your post but for future reference this forum post tells you how to add code to the forum: https://teamtreehouse.com/forum/posting-code-to-the-forum