YOUR SAVED CODE-ALONG
Find a longest word with Rob: workspace
Keep the lesson open on your other screen. Your edits stay in this workspace, separate from the practice activity. Sign in to save and reload a private account draft across devices, or share a snapshot when you need help.
CODE-ALONG / THEATER MODE
Find a longest word with Rob
ORIGINAL WALKTHROUGH · 12:43
Watch with Rob.
Pause whenever you want to try a change. You can return to the lesson at any time.
You are signed in, but video access needs attention. Check your account access. Your saved work is kept.
Video walkthroughs are included with an active Code Zone membership. The written lesson and practice are free.
Video settings & progress
Your lesson progress
Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.
Start the video to enable typing controls.
YOUR TURN
Find a longest word with Rob: workspace
Write largestWord(str), returning the longest word in a string. If several words have the same greatest length, return the first. Start with I am a coding ninja, which should return coding. Also try red sun, which should return red. For this companion, split on spaces, keep punctuation in tokens and use basic Latin text. This separate code-along is exploratory; use the companion practice for graded output checks.
Load an example, edit it and run it. Word wrap is enabled.
Your check results
Work in VS Code instead
Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.
/*
Write largestWord(str), returning the longest word in a string. If several words have the same greatest length, return the first. Start with I am a coding ninja, which should return coding. Also try red sun, which should return red. For this companion, split on spaces, keep punctuation in tokens and use basic Latin text.
*/
function largestWord(str) {
let largest = "";
// Split the phrase and update your candidate here.
return largest;
}
// Log largestWord("I am a coding ninja") when ready.Lesson reference
Examples load into this same code-along only after you confirm replacing your code.
Find the first longest word
Work through 5 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)5 steps · Saved work · Instant feedback
Inspect the words and their lengths
The original challenge asks for the longest word, returning the first one if several words share the greatest length. In the original phrase, coding has six letters and ninja has five.
Run this length inventory, then trace a separate candidate as you visit I, am, a, coding and ninja. The candidate should change to I, then am, then coding; it should stay coding at ninja.
const words = "I am a coding ninja".split(" ");
for (const word of words) {
console.log(word + ": " + word.length);
}A second input tests the tie rule
For red sun, both lengths are 3. Keep red because it appears first. Use this case to check the comparison rather than assuming one passing example proves the whole function.
The original assignment accepted a JSFiddle or GitHub URL. Here, signed-in learners can submit their code directly for instructor review. The separate workspace starts with the original phrase and a runnable function stub.
See the attached lesson’s comic
