Emperor01 / JSlearn

all my practical trainings
0 stars 0 forks source link

make str is shorter #6

Open Emperor01 opened 6 years ago

Emperor01 commented 6 years ago

function truncate (str, maxlength) { if (str.length > maxlength) { str = str.slice(0, maxlength - 3) + "..."; }

return str; }

alert(truncate('I buy some apples to myself', 20));