Truncating strings help!

Truncating strings help!
0

#1

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:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/truncate-a-string/


#2

I am certain you are not using slice correctly.


#3

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


#4

I only see one argument being passed.


#5

Capture


#6

You are misinterpreting how it works.

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


#7

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


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

console.log(animals.slice(2));
// expected output: Array ["camel", "duck", "elephant"]

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


#9

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