Please i'm trouble how can i do it
this is my function
function truncate(num) {
var str;
if (str.length > num && num > 3) {
console.log(str.length);
return str.slice(0, num) + "...";
} else if (str.length > num && num <= 3) {
console.log('ok');
return str.slice(0, num) + "..."
} else {
console.log(str.length);
return str;
}
}
i want to execute my function on a string like that console.log('hello world!'.truncate(2));
Please any body can help me, thanks