Find the longest word in the string


Find the longest word in the string

let str = 'practice makes perfect';
let words = str.split(' ');
let longestWord = '';

for(let word of words) {
  if(word.length > longestWord.length) {
    longestWord = word;
  }
}

console.log(`Longest words is: ${longestWord}`);