Skip to content
Advertisement

Splitting a string before finding longest word

I have read a few different posts on this so I am sorry to ask this again but none seemed to solve my issue.

I’m trying to draw out the length of the longest word in a string, that is coming from HTML.

All I can get is, “Uncaught TypeError: Cannot read property ‘split’ of undefined”

The HTML:

JavaScript

The JS:

JavaScript

Advertisement

Answer

Using reduce as Adrian explained is a great way to achieve your goal in JS.

But if your target was to learn some of the basics of coding, here are some hints on how to make your current code work.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement