Getting a TypeError: str.slice is not a function. can someone explain why this isn’t working?
Your code so far
const truncateString = (str,num)=> {
let shortString = str.slice(0,num);
let truncate = shortString + "...";
if (str.length >= num && str.length){
return truncate}
else if (str.length <= num){
return str
}
};
console.log(truncateString("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/137.0.0.0 Safari/537.36
Challenge Information:
Implement the Truncate String Algorithm - Implement the Truncate a String Algorithm
Right! it should be ;
console.log(truncateString(“A-tisket a-tasket A green and yellow basket”,“A-tisket a-tasket A green and yellow basket”.length));
and then it returns ;
A-tisket a-tasket A green and yellow basket…
but I am only wanting it to console.log “A-tisket a-tasket A green and yellow basket” and I am seeing that I need to added a 3rd condition on the if else statment, but haven’t figured that out yet.