Truncate a string - I solved this but didn't understand the logic of using num instead of num.length

Truncate a string - I solved this but didn't understand the logic of using num instead of num.length
0

#1

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);


#2

The num variable passed into the function repeat is an integer. Not sure what value num.length was giving you, but it should have been undefined. The length property is meant to work with strings such as str in this challenge.


#3

Yes I see now, I guess so, but it was only needed 2 statemements, the 1st one didn’t do any difference.