Tell us what’s happening:
Hey, I struggled with this one as I wasn’t sure what It was asking me to do, none the less all I could find was solutions on the web. Having put some of those in the console it still doesn’t pass. If there a problem with it? or has it been updated and requires additional thinking? Btw the solution code was from the “Get a Hint” button
Your code so far
function truncateString(str, num) {
// Clear out that junk in your trunk
if (str.length > num && num > 3) {
return str.slice(0, (num - 3)) + ‘…’;
} else if (str.length > num && num <= 3) {
return str.slice(0, num) + ‘…’;
} else {
return str;
}
}
truncateString(“A-tisket a-tasket A green and yellow basket”, 11);
function truncateString(str, num) {
// Clear out that junk in your trunk
if (str.length > num && num > 3) {
return str.slice(0, (num - 3)) + '...';
} else if (str.length > num && num <= 3) {
return str.slice(0, num) + '...';
} else {
return str;
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 11);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/truncate-a-string