I checked the documentation for slice function, and it doesn’t say the endpoint need to be smaller than string length. I tried my code in MDN String.prototype.slice() documentation, and it works fine. But not in freecodecamp, so I am really confusing why do we need to make sure the the str.length is bigger than the number to do the slice?
Following are the code I tested in MDN.
> var str = 'A-tisket a-tasket A green and yellow basket';
>
> console.log(str.slice(0, "A-tisket a-tasket A green and yellow basket".length+2));
> //output: "A-tisket a-tasket A green and yellow basket"
In the challenge you have a string and a max length, and if the string is longer than the max length you need to truncate the string and add dots at the end - if the string doesn’t exceed that length than the dots shouldn’t be allowed.
So it is not the slice method that needs the check, because if the length added in the slice is longer than the string length it returns the whole string - it is adding the dots or not that need the check