Tell us what’s happening:
please somebody help me out have i written something wrong
Your code so far
function truncateString(str, num) {
if (str.length <= num) {
return str;
} else if (num > 3) {
return str.slice(0, num - 3) + "...";
} else {
return str.slice(0, num) + "...";
}
}
console.log(truncateString("A-tisket a-tasket A green and yellow basket", 8));
console.log(truncateString("Peter Piper picked a peck of pickled peppers", 11));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Challenge Information:
Implement the Truncate String Algorithm - Implement the Truncate a String Algorithm