Basic Algorithm Scripting - Truncate a String

function truncateString(str, num) {
  return `${str.slice(0,num)}...`;

console.log(truncateString("A-tisket a-tasket A green and yellow basket","A-tisket a-tasket A green".length + 2));

What is Wrong with this code It as pass the test but not accepted by freeCode Camp
Check It Out

The problem is that you are adding the elipsis to the string regardless of length.

The directions say to only truncate the string if it is longer than the given maximum string length (num)

You will need to add a condition to your code to get it working the way it should, then it will pass.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.