Advertisement
Liliana797979

viarno reshenie count the words

Feb 7th, 2021
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.      
  3. function countTheWords(input){
  4.  
  5.     let text = (input[0]);
  6.     let words = 1;
  7.  
  8.  
  9.     for (let i = 1; i <= text.length; i++){
  10.  
  11.         if (text.charAt(i) === " "){
  12.  
  13.             words += 1;
  14.         }
  15.     }
  16.  
  17.     if (words > 10){
  18.  
  19.         console.log(`The message is too long to be send! Has ${words} words.`);
  20.     } else {
  21.  
  22.         console.log(`The message was send successfully!`);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement