hello fellow coders, i dont know whats wrong with this. i tried all i can but it kept failing the test 1 and 2 (note: it passed others just the 1 & 2) please help out.
Your code so far
function truncateString(str, num) {
if (str.length <= num) {
return str;
} else {
return str.slice(0, num > 3 ? num - 3 : num) + '...';
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36.
I think it maybe a carryover from the old curriculum, I vaguely remember a modified version of this problem with length 3 as some type of constraint or another.
@p-gold If your question is how that solution worked or is supposed to work, I can understand, but if you are just copying it to pass the challenge, I encourage you to better understand how.slice() works for strings and ask for elaborations from the forum if need be, otherwise you will only be robbing your self of the opportunity to learn, which will most definitely come back to bite you later on down the line.