Javascript : Basic Algorithm Scripting: Truncate a String

Solution in Hint does not work.
Here’s what will pass the test:

function truncateString(str, num) {
var firstPart="";
var truncatedStr="";
if(str.length<=num){
truncatedStr = str;
}else if(str.length>num){
firstPart = str.slice(0, num);
truncatedStr = firstPart+"…";
}else{
truncatedStr = str+"…";
}
return truncatedStr;
}

Plus, really easy to read (for newbies like me).

1 Like

Yes, the hint is incorrect, it is based on an old version of the problem. The hints aren’t as well maintained as the curriculum.