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

Tell us what’s happening: Please show me why this dont pass step 3 and 4

function truncateString (str, num) {
if (str.length <= num) {
return console.log(str);
} else if (str.length > num) {
var result = str.substring(0, num) + “…”;
return result;
}
}

Your code so far

function truncateString (str, num) {
  if (str.length <= num) {
    return console.log(str);
  } else if (str.length > num) {
    var result = str.substring(0, num) + "...";
    return result;
  }
}

Your browser information:

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

Challenge Information:

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

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

because if I test with console.log(truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length)), your function is returning undefined

removed by moderator

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.