Implement the Truncate String Algorithm - Implement the Truncate a String Algorithm

Tell us what’s happening:

I am able to get all the output that I am supposed to get. However, I still fail all the tests. I’m not sure why I’m failing the tests if my output is showing as correct.

Your code so far

function truncateString(string, num) { 
  let newStr;
  if (string.length > num) {
    newStr = string.slice(0, num);
    return console.log(newStr + "...");
  }
  else {
    newStr = string;
    return console.log(newStr);
  }
}

  let string = ""; 
truncateString("A-tisket a-tasket A green and yellow basket", 8);

truncateString("Peter Piper picked a peck of pickled peppers", 11);
truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length);
truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2)
truncateString("A-", 1)
truncateString("Absolutely Longer", 2)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:144.0) Gecko/20100101 Firefox/144.0

Challenge Information:

Implement the Truncate String Algorithm - Implement the Truncate a String Algorithm

This doesn’t do what you think it does

Thank you. At first, I wasn’t sure what you were getting at. I updated my variable newStr to string in case the code was checking to see that I was actually using string. That didn’t work either. Apparently, the code did not want output. I understood what I was doing. I did not understand the directions.

what do you expect returning console.log to do?

I expect it to output on the right-hand side. For some reason, I thought I needed output to complete the goal. I realized, though, that there are times you want things to run in the background and not everything needs to be visible.