Truncate a String0

Tell us what’s happening:

Help me out with this and Thanks in advance.

Your code so far

function truncateString(str, num) {
  // Clear out that junk in your trunk
  if (str.length <= num) {
      return str;

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0.

**Link to the challeng

Instead of us giving you the answer, have you developed a written algorithm (no code) with the necessary steps/logic that would be need to solve the challenge?

Do you understand what must be done if str.length is greater than num?

I did not understand, explain me what to do if str.length > num. i will write the code

You need to make the string shorter (the length is num) and add three dots at the end to show that you have shortened the string

still these first two test cases are not working. if there is something wrong or need an explanation please let me know.

What new code have you tried? Post your newest version.

What happens if str.length is less than or = 3?

it returns str in the else part

Doesn’t it need “…” somewhere?

console.log(truncateString(“A-tisket a-tasket A green and yellow basket”, 8));
returns: A-tis… (with your code).
which is 8 characters, but you want 8 characters + “…”
Look at your first if statement (does num have to be > 3?). Then edit the return for the first if statement accordingly.

Edit: My answer was for code in another question that was referring to the “hint answer” that got merged with this question because it was a duplicate. So what I said above refers to the hint answer.

Your issue is still the same, you can’t use the solution from the guide, because t counts the dots inside the limit of characters. Instead the length of the str is max num and after truncated you add the dots