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="";
truncatedStr = str;
}else if(str.length>num){
firstPart = str.slice(0, num);
truncatedStr = firstPart+"…";
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.