Tell us what’s happening:
The code I came up with, which is the same as the answers given, do not pass all the tests. I can’t think of another solution to pass two of the failing tests. Even with the same exact code (both answers that are given in the hints) don’t pass the two tests. Seems like a bug to me.
Your code so far
function truncateString(str, num) {
// Clear out that junk in your trunk
if (str.length > num && num > 3) {
return str.slice(0, (num - 3)) + '...';
}else if (str.length > num && num <=3) {
return str.slice(0, num) + '...';
}else {
return str;
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/truncate-a-string