I passed the test with this code except for when it ran:
1). truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length) should return “A-tisket a-tasket A green and yellow basket”.
2). truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2) should return “A-tisket a-tasket A green and yellow basket”.
Any advice for alterations that need to be done to fully complete the challenge?
Your code so far
function truncateString(str, num) {
if (num >= str.lenght) {
return str ;
} else {
str = str.substring(0,num);
return str+ "...";
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.
Challenge: Truncate a String
Link to the challenge: