Aside: Wondering what the "undefined" is that shows up whenever we use console.log? It is just the return value of that method and can be ignored. This editor always outputs the return value of the last computed statement, which is how it was possible to display certain values without using console.log earlier in the tutorial.
Now you have all of the tools needed to create a function that gets the longest word of a sentence and displays it. There are many ways to do this, but if you do not know where to begin, here is one idea:
- Split the sentence string into an array of words
- Create a variable to hold your current maximum length word
- Assume the first word (at index 0) is the maximum length word
- Loop through each word in the array
- if the current word is longer than the word in your maximum variable
- set maximum to the current word
- Display the value of the variable containing the longest word