Basic Algorithm Scripting - Truncate a String

My code worked but it does not seem completely right to me. I don’t understand how it met the fourth criteria of the challenge. Can somebody please explain?

Your code so far

function truncateString(str, num) {
  let truncated = str.substring(0, num);
  let final = truncated + "...";
  if (str.length <= num) {
    return truncated;
  }
  return final;
}
console.log(truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2));
  



Your browser information:

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

Challenge Information:

Basic Algorithm Scripting - Truncate a String

I don’t if this helps but you could just console.log the given string without any code, so to answer your question this is just passing the requirments. Good luck

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