I think I may have a problem with the “return” keywords. I’m not really sure where I went wrong with this one. Any help would be much appreciated!
function truncateString(str, num) {
if(str.length > num.length){
return str.slice(0, num.valueOf())+"...";
}else {
return str.slice(0, num.valueOf())
}
}
console.log(truncateString("A-tisket a-tasket A green and yellow basket", 8));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.1 Safari/605.1.15
Challenge: Basic Algorithm Scripting - Truncate a String
Link to the challenge: