why is my codes not passing after writing all this…
Your code so far
function truncateString(str, num) {
if(str.length<=num)
{
console.log(str);
return str;
}
else
{
if(str.length<3 || num<3){
str=str.slice(0,num)+"...";
}
else
{
str=str.slice(0,num-3)+'...';
}
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 2);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Truncate a String
Link to the challenge: