0Pricing
Javascript for Kids · Lesson

Longest Word

Find the longest.

Longest Word is a free Javascript for Kids lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Javascript for Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Find the Longest Word! 📏

Hello, word champion! 📝 Today is a fun challenge: find the longest word in a sentence! 📏

Which word has the most letters? Let's teach the computer to find it! 🔍

Split First ✂️

To compare words, we first split the sentence into a list. ✂️

You know this trick now! split(' ') gives us our words. 📋

let sentence = 'the happy elephant';
let words = sentence.split(' ');
console.log(words);

Compare Two Words ⚖️

To find the longest, we compare lengths! ⚖️

We check: is 'elephant' longer than 'cat'? 🐘 vs 🐱

let word1 = 'elephant';
let word2 = 'cat';
if (word1.length > word2.length) {
  console.log(word1 + ' is longer! 🐘');
} else {
  console.log(word2 + ' is longer! 🐱');
}

Keep a Champion 🏆

To find the longest in a whole list, we keep a champion! 🏆

We start with the first word as champion, then see if anyone beats it! 💪

let words = ['cat', 'elephant', 'dog'];
let longest = words[0];
console.log('Champion starts as: ' + longest);

Check Each Word 🔁

Now we loop through every word and check it! 🔁

If a word is longer than our champion, it becomes the new champion! 👑

let words = ['cat', 'elephant', 'dog'];
let longest = words[0];
for (let i = 0; i < words.length; i = i + 1) {
  if (words[i].length > longest.length) {
    longest = words[i];
  }
}
console.log('The longest word is: ' + longest + ' 🏆');

Try Your Own Sentence 📜

Let's find the longest word in a full sentence! 📜

Split it, then loop to find the champion! 👑

let sentence = 'I really love programming';
let words = sentence.split(' ');
let longest = words[0];
for (let i = 0; i < words.length; i = i + 1) {
  if (words[i].length > longest.length) {
    longest = words[i];
  }
}
console.log('Longest word: ' + longest);

Show its Length Too 📏

Let's also show how many letters the winner has! 📏

Now we know the word AND its size! 🔢

let words = 'a tiny wonderful day'.split(' ');
let longest = words[0];
for (let i = 0; i < words.length; i = i + 1) {
  if (words[i].length > longest.length) longest = words[i];
}
console.log('🏆 Longest: ' + longest);
console.log('✏️ Letters: ' + longest.length);

Make a Finder Machine 🛠️

Let's turn it into a reusable machine! 🛠️

Give it a sentence, get back the longest word! 🤖

function findLongest(sentence) {
  let words = sentence.split(' ');
  let longest = words[0];
  for (let i = 0; i < words.length; i = i + 1) {
    if (words[i].length > longest.length) longest = words[i];
  }
  return longest;
}
console.log(findLongest('the quick brown fox'));

Test Your Machine 🧪

Let's test our finder on different sentences! 🧪

It always finds the longest word, no matter the sentence! 🎯

function findLongest(sentence) {
  let words = sentence.split(' ');
  let longest = words[0];
  for (let i = 0; i < words.length; i = i + 1) {
    if (words[i].length > longest.length) longest = words[i];
  }
  return longest;
}
console.log(findLongest('big bigger biggest'));
console.log(findLongest('sun moon stars galaxy'));

The Full Word Counter App 🎮

Let's put EVERYTHING together: word count, letter count, and longest word! 🎮

You built a complete app! 💪

function analyze(sentence) {
  let words = sentence.split(' ');
  let longest = words[0];
  for (let i = 0; i < words.length; i = i + 1) {
    if (words[i].length > longest.length) longest = words[i];
  }
  console.log('🔢 Words: ' + words.length);
  console.log('🔠 Letters: ' + sentence.split(' ').join('').length);
  console.log('🏆 Longest: ' + longest);
}
analyze('coding makes everything fun');

You Built a Word Counter! 🏆

AMAZING! 🏆 You finished the whole Word Counter app!

  • ✂️ Split sentences into words
  • 📏 Count words and letters
  • 👑 Find the longest word with a loop

You are a true text master! 📝

Quick Check ✅

Final brain check! 🧠 How do we find the longest word in a list?

Lesson Recap 🎀

Hooray, word master! 🎀 You completed the Word Counter! You learned:

  • ✂️ Split into a list of words
  • ⚖️ Compare lengths with >
  • 👑 Keep a champion in a loop
  • 🛠️ Wrap it in a function

Incredible work! 🌟

Frequently asked questions

Is the “Longest Word” lesson free?

Yes — the full text of “Longest Word” is free to read here on the web, and the Javascript for Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Javascript for Kids course, upgrade to CoddyKit PRO.

What will I learn in “Longest Word”?

Find the longest. You practise Javascript for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Javascript for Kids?

No prior experience is required. Javascript for Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Longest Word” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Javascript for Kids lesson?

Yes. Every Javascript for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Splitting Text
  2. Counting Words
  3. Counting Letters
  4. Longest Word
← Back to Javascript for Kids