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

let string='Joe' alert(string.length.toString(string.length)). Why it is not returning a string number three?

<script>
let string='Joe'
alert(string.length.toString(string.length)). Why it is not returning a string number two?
/*
How it is possible to use method on a property like classList?
</script>

1 Answer

Cameron Childres
Cameron Childres
11,818 Points

Hi there,

I'm not sure if I can fully answer your question but I can offer a bit of information on why your code returns "10" instead of "3".

Take a look at "parameters" under the toString() method documentation. Passing a number to toString() sets the radix for the conversion, determining the base of the number system that will be used.

Referring to the code inside your alert:
string.length.toString(string.length)
Since the length of the string "Joe" is 3 you can rephrase this as "convert the number 3 to a string in base 3 (ternary)". In ternary the number 3 is represented as 10.