question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suboptimal wording for JS: Find the Length of a String

See original GitHub issue

One 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 the lastName variable and assign it to lastNameLength.

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 the lastName variable, then assign that length to lastNameLength.

Affected page

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
lynxlynxlynxcommented, Mar 21, 2022

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

0reactions
jeremyltcommented, Mar 30, 2022

Or here’s a similar wording:

Use the .length property to set lastNameLength to the number of characters in last Name

I like this one if we’re going to change it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found