Tell us what’s happening:
Can anyone verify if the below mentioned code is also a valid solution to the truncate a string challenge?
Your code so far
function truncateString(str, num) {
// Clear out that junk in your trunk
if (str.length > num){
let sl1 = str.slice(0,num);
return sl1 +"..."
}
let sl2 = str.slice(0,num);
return sl2
}
console.log(truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
.
Link to the challenge: