Truncate a string close but not quite

Truncate a string close but not quite
0

#1

Can’t quite figure what’s missing, any insight would be appreciated, thanks in advance.

function truncateString(str, num) {
  if (str.length <= num){
    return str.slice(0, num) + "...";
  } else if (str.length > num) {
    return str.slice(0, num-3) + "...";
  } else {
              
            }
  return str;
}

#2

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.


#3

The way I did it, I made a three-way fork. I returned a value if str.length <= num, another value if num <= 3, and yet another for all other cases.