Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findLongestWord(str) {
- //Make string into array, with each word as an array value
- var strArray = str.split(" ");
- //Create variable to hold value of longest word
- var longestWord = 0;
- //Iterate through the array and find the length of each value to determine longest word
- for (var i = 0; i < strArray.length; i++) {
- if (strArray[i].length > longestWord) {
- longestWord = strArray[i].length;
- }
- }
- return longestWord;
- }
- findLongestWord("The quick brown fox jumped over the lazy dog");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement