I’m having trouble with two of the tests that are the complete length of the string so it is not truncated.
Can anyone tell me why my code is failing the two tests?
Thanks.
function truncateString(str, num) {
// Clear out that junk in your trunk
if (num >= str.length){
return str + "..."
}
else if (str.length > num){
return str.slice(0, num) + "...";
}
else{
return str;
}
}
This got rid of one of the two but the one that is .length +2 is failing
function truncateString(str, num) {
// Clear out that junk in your trunk
if (num > str.length && num !>= str.length){
return str + "..."
}
else if (str.length > num){
return str.slice(0, num) + "...";
}
else{
return str;
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);