I’ve tried to figure this one out…was confident I had it, but couldn’t get my solution to pass. Then I tried running a solution from “Get a hint”, which was similar to mine, and that solution doesn’t pass either. The code below is taken from the “Get a hint” page and is not passing the challenge.
Your code so far
function truncateString(str, num) {
if (str.length <= num) {
return str;
} else {
return str.slice(0, num > 3 ? num - 3 : num) + '...';
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:63.0) Gecko/20100101 Firefox/63.0.
It seems it is for counting the 3 dots in the character limit (so 5 characters from the original string and 3 for the dots in the case there that there are 8 characters max), but the challenge doesn’t ask for that, so it is decisively wrong - someone may need to change that hint/solution
This challenge has changed since the solution was written. Originally, the elipsis was considered part of the length, but that added confusion. If you would like to update the guide, you can revise the article and submit a pull request.