Suboptimal wording for JS: Find the Length of a String
See original GitHub issueOne of my students got stuck on this exercise, but it turned out to be a spoken language issue, not one of programming.
Use the
.length
property to count the number of characters in thelastName
variable and assign it tolastNameLength
.
They understood the task as being to find the length of lastName
, but then to still assign lastName
itself to lastNameLength
. So exactly the pedantry we want to teach, uncovering undefined behaviour. 😃
I suggest changing the text to be more explicit:
Use the
.length
property to count the number of characters in thelastName
variable, then assign that length tolastNameLength
.
Affected page
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
String length - JavaScript - MDN Web Docs - Mozilla
This property returns the number of code units in the string. JavaScript uses UTF-16 encoding, where each Unicode character may be encoded ...
Read more >Finding longest string in array - javascript - Stack Overflow
Available since Javascript 1.8/ECMAScript 5 and available in most older browsers: var longest = arr.reduce( function (a, b) { return a.length > b.length...
Read more >JavaScript String Length property explained | Flexiple Tutorials
The length of a string in JavaScript can be found using the .length property. Since .length is a property it must be called...
Read more >Get shortest/longest string in array - Julia Discourse
What is the best way to retrieve the shortest or longest string in an array? If there are multiple candidates having the same...
Read more >How to get the length of a string in JavaScript? - Tutorialspoint
By knowing an easy method to calculate the length of a string in JavaScript, we can increase or decrease the words and phrases....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Keep in mind, it might be obvious to us who have experience and great or native English proficiency, which was not true in this case (let’s say B2 for language and almost zero programming experience). After spending over 15 minutes on something like this, frustrated why the test is failing, I doubt anyone would remember how the original seed looked like. The instructions can be legitimately read so that
lastNameLength = lastName
is the expected solution. Hence the suggestion for change (though I’m not married to particular wording).I like this one if we’re going to change it.