Guest User

Untitled

a guest
Dec 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. function findLongestWord(str) {
  12. var words = str.split(' ');
  13. var maxLength = 0;
  14. for (var i = 0; i< words.length; i++) {
  15. if (words[i].length > maxLength) {
  16. maxLength = words[i].length;
  17. }
  18. }
  19. return maxLength;
  20. }
  21.  
  22. console.log(findLongestWord("The quick brown fox jumped over the lazy dog"));
  23. console.log(findLongestWord("What if we try a super-long word such as otorhinolaryngology"));
  24. </script>
  25.  
  26.  
  27.  
  28. <script id="jsbin-source-javascript" type="text/javascript">function findLongestWord(str) {
  29. var words = str.split(' ');
  30. var maxLength = 0;
  31. for (var i = 0; i< words.length; i++) {
  32. if (words[i].length > maxLength) {
  33. maxLength = words[i].length;
  34. }
  35. }
  36. return maxLength;
  37. }
  38.  
  39. console.log(findLongestWord("The quick brown fox jumped over the lazy dog"));
  40. console.log(findLongestWord("What if we try a super-long word such as otorhinolaryngology"));
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. </script></body>
  49. </html>
Add Comment
Please, Sign In to add comment