function truncateString(str, num) {
// Clear out that junk in your trunk
if (str.length <= num) {
return str;
}
else
{
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0.
console.log(truncateString(“A-tisket a-tasket A green and yellow basket”, 8));
returns: A-tis… (with your code).
which is 8 characters, but you want 8 characters + “…”
Look at your first if statement (does num have to be > 3?). Then edit the return for the first if statement accordingly.
Edit: My answer was for code in another question that was referring to the “hint answer” that got merged with this question because it was a duplicate. So what I said above refers to the hint answer.
Your issue is still the same, you can’t use the solution from the guide, because t counts the dots inside the limit of characters. Instead the length of the str is max num and after truncated you add the dots