1

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

irkoch
  • 75
  • 9
  • You would need to make `truncate` part of the String prototype to run it that way. Passing the string in as a param would be easier. `truncate(myString, num)` – jmargolisvt Mar 03 '19 at 19:17

0 Answers0