Tell us what’s happening:
I need the test to return “Peter Piper…”, but it returns “Peter Piper pi…”. Any ideas how I can reduce the slice() 3 more characters?
Your code so far
function truncateString(str, num) {
if (str.length > num){
var a = str.slice(0, num) + '...';
return a;
}
else if (str.length <= num){
var b = str.slice(0, num);
return b;
}
}
truncateString("Peter Piper picked a peck of pickled peppers", 14);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/truncate-a-string