Truncate a string mysterious results

Truncate a string mysterious results
0

#1

It is somehow returning “P” on the second to last test. It also says it doesn’t return “Ab” if I run the last test. I can’t seem to figure out what is going on here that it would return a letter not even given to it.

Your code so far

function truncateString(str, num) {
  // Clear out that junk in your trunk
  
    if (str.length > num) {
      if (num <= 3) {
        string = string.slice(0, num);
        return string + "...";
      }
      else {
        string = str.slice(0, num - 3);
    return string + "...";
      }
    
  } else {
    return str;
  }
}

truncateString("A-", 1);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36.

Link to the challenge:


#3

I don’t know how I missed that, thanks a lot!