File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ <!--  
2+ 
3+  freeCodeTask: 
4+  Truncate a string (first argument) if it is longer than the given maximum string length  
5+  (second argument). Return the truncated string with a ... ending. 
6+ 
7+  --> 
8+ 
9+ <!DOCTYPE html>  
10+ < html  lang ="en "> 
11+ < head > 
12+  < meta  charset ="UTF-8 "> 
13+  < meta  http-equiv ="X-UA-Compatible " content ="IE=edge "> 
14+  < meta  name ="viewport " content ="width=device-width, initial-scale=1.0 "> 
15+  < title > Truncate a string</ title > 
16+ </ head > 
17+ < body > 
18+  
19+ </ body > 
20+ < script > 
21+  function  truncateString ( str , num ) { 
22+  if ( str . length  >  num ) { 
23+  return  str . slice ( 0 ,  num )  +  "..." ; 
24+  } else  { 
25+  return  str 
26+  } 
27+  } 
28+ 
29+  console . log ( truncateString ( "A-tisket a-tasket A green and yellow basket" ,  8 ) ) 
30+ </ script > 
31+ </ html > 
                         You can’t perform that action at this time. 
           
                  
0 commit comments