truncateString("A-tisket a-tasket A green and yellow basket", 8) should return "A-tisket...". truncateString("Peter Piper picked a peck of pickled peppers", 11) should return "Peter Piper..."

Tell us what’s happening:

Your code so far


function truncateString(str, num) {
  if (str.length <= num) {
    return str;
  } else {
    return str.slice(0, num > 3 ? num - 3 : num) + '...';
  }
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/truncate-a-string

what kind of help do you need?

when i run the code " truncateString(“A-tisket a-tasket A green and yellow basket”, 8) should return “A-tisket…”.
truncateString(“Peter Piper picked a peck of pickled peppers”, 11) should return “Peter Piper…”. i do not know what to do .

you need to reduce the string to the max number of characters requested. But there isn’t much you can do to a string, so you can try first splitting it up in an array. Now try yourself thinking on how you can manipulate the array to get the output you need

Useful links: String split() Method; Array join() Method (because your output needs to be a string)

Or an other useful link is this one: String slice() method - with this you needs less steps to solve

You can do it!

thanks so much @ieahleen i know now i limited num > 3 )))
i have got one Certification ,but i can see it on the system where can i see it?