Bonfire: Find the Longest Word in a String, Difficulty: 1

Return the length of the longest word in the provided sentence.

Your response should be a number.



My solution:

function findLongestWord(str) {

Progra//split string and placed in array
var array1 = str.split(‘ ‘);
var word = array1[0];

//compare strings in array
for (var i = 0; i < array1.length; i++)
if(word.length < array1[i].length)
word = array1[i];

return word.length;

findLongestWord(‘The quick brown fox jumped over the lazy dog’);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s