Tell us what’s happening:
I was able to come out with the solution. However i could not understand the usage of the number 3 which everyone is using in the official thread below.
https://forum.freecodecamp.org/t/freecodecamp-algorithm-challenge-guide-truncate-a-string/16089
Am i missing something or is there a problem with my solution?
Thanks in advance.
Your code so far
function truncateString(str, num) {
// Clear out that junk in your trunk
if (num >= str.length) {
return str;
}
else {
str = str.slice(0 , num)+"...";
}
return str;
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; 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