Truncating strings help!

Tell us what’s happening:
Doesn’t return the correct value

Your code so far

function truncateString(str, num) {
  // Clear out that junk in your trunk
  if (str.length <= num) {
    return str;
  } else {
    return str.slice(num + 1) + '...';

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/68.0.3440.84 Safari/537.36.

Link to the challenge:

I am certain you are not using slice correctly.

I don’t know what is wrong with my slice. I specify where to start and to cut out the rest of the string.

I only see one argument being passed.


You are misinterpreting how it works.

Did you read the link to the documentation I gave? What does the example show you?

I did read it a bit, I don’t think i found anything useful

var animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];

// expected output: Array ["camel", "duck", "elephant"]

Is this the kind of behavior you want in your current code?

1 Like

Ahh, I see, it takes out what isn’t specified. I though it did the opposite.
Thanks I understand now.

1 Like