I replaced num.length for num, but still don’t understand why it works in the num variables which have length in it, since they were the 2 conditions which were working. Furthermore, I changed the order of the first if statement, being num in first. Here is my code:
function truncateString(str, num) {
// Clear out that junk in your trunk
if(num>=str.length){
str=str.slice(0);
}
else if(num<=3){
str=str.slice(0,num).concat("…");
}
else{
str=str.slice(0,num-3).concat("…");
}
return str;
}
truncateString(“A-tisket a-tasket A green and yellow basket”, 11);