functionlongestWord(str) {
// split the string into an array of wordsvar words = str.split(" ");
// variable to store the longest wordvar longest = "";
// loop through each wordfor (var i = 0; i < words.length; i++) {
// if the current word is longer than the longest word, update longestif (words[i].length > longest.length) {
longest = words[i];
}
}
// return the longest wordreturn longest;
}
// Example usage:var str = "The quick brown fox jumped over the lazy dog";
console.log(longestWord(str)); // Output: "jumped"